{{! ========================================================== }}
{{! ========================================================== }}
{{! ==================Helmrepo channel ==================== }}
{{! ========================================================== }}
{{! ========================================================== }}

{{#unless channelNamespace}}
{{#unless channelNamespaceExists}}
---
apiVersion: v1                      
kind: Namespace
metadata:
  name: {{{channelName}}}-ns
{{/unless}}
---
apiVersion: apps.open-cluster-management.io/v1
kind: Channel
metadata:
  name: {{{channelName}}}
  namespace: {{{channelName}}}-ns
  {{#if selfLinks}}
  selfLink: {{{selfLinks.Channel}}}
  {{/if}}
spec:
  type: HelmRepo
{{#if helmURL}}
  pathname: '{{{helmURL}}}'
{{/if}}
{{#if helmInsecureSkipVerify}}
  insecureSkipVerify: true
{{/if}}
{{#if helmUser}}
  secretRef:
    name: {{{channelName}}}-auth
---
apiVersion: v1
kind: Secret
metadata:
  name: {{{channelName}}}-auth
  namespace: {{{channelName}}}-ns
data:
  user: {{{helmUser}}}
  password: {{{helmPassword}}}
{{/if}}
{{/unless}}      
---
apiVersion: apps.open-cluster-management.io/v1
kind: Subscription
metadata:
  labels:
    app: {{{@root.name}}}
  name: {{{@root.name}}}-subscription-{{uniqueGroupID}}
  namespace: {{{@root.namespace}}}
  {{#if selfLinks}}
  selfLink: {{{selfLinks.Subscription}}}
  {{/if}}
spec:
{{#if ansibleSecretName}} 
  hooksecretref: 
    name: {{{ansibleSecretName}}}
{{/if}}
{{#if channelNamespace}}
  channel: {{{channelNamespace}}}/{{{channelName}}}
{{else}}
  channel: {{{channelName}}}-ns/{{{channelName}}}
{{/if}}
{{#if helmChartName}}
  name: {{{helmChartName}}}
{{/if}}
  packageOverrides:
  - packageName: {{{helmChartName}}}
{{#if helmPackageAlias}}
    packageAlias: {{{helmPackageAlias}}}
{{/if}}
{{#if helmPackageVersion}}
  packageFilter:
    version: "{{{helmPackageVersion}}}"
{{/if}}
