validatedpatterns / common

Apache License 2.0
2 stars 20 forks source link

trailing zero is removed from channel in subscription #295

Open Ladanow opened 1 year ago

Ladanow commented 1 year ago

Hi

When we have a channel like 4.10, it is translated into Argo as 4.1

a workaround was set to use "4.10" and it worked.

apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: openshift-performance-addon-operator-subscription
  namespace: openshift-performance-addon-operator
spec:
  channel: "4.10"
  name: performance-addon-operator
  source: redhat-operators
  sourceNamespace: openshift-marketplace
claudiol commented 1 year ago

@Ladanow Our current subscription template has the following to generate the channel:

# Source: clustergroup/templates/core/subscriptions.yaml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: {{ $subs.name }}
  namespace: {{ . }}
spec:
  name: {{ $subs.name }}
  source: {{ default "redhat-operators" $subs.source }}
  sourceNamespace: {{ default "openshift-marketplace" $subs.sourceNamespace }}
  {{- if $subs.channel }}
  channel: {{ $subs.channel }}
  {{- end }}

Proposed fix: @mbaldessari

One solution is to add the quote filter to the template like so:

# Source: clustergroup/templates/core/subscriptions.yaml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: {{ $subs.name }}
  namespace: {{ . }}
spec:
  name: {{ $subs.name }}
  source: {{ default "redhat-operators" $subs.source }}
  sourceNamespace: {{ default "openshift-marketplace" $subs.sourceNamespace }}
  {{- if $subs.channel }}
  channel: {{ $subs.channel | quote }}
  {{- end }}

So if you define the subscription in the values file like so:

    example:
      name: example-sub
      namespace: example-sub
      channel: 4.10

The framework will generate the following:

---
# Source: pattern-clustergroup/templates/core/subscriptions.yaml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: example-sub
  namespace: example-sub
spec:
  name: example-sub
  source: redhat-operators
  sourceNamespace: openshift-marketplace
  channel: "4.10"
  installPlanApproval: Automatic
mbaldessari commented 1 year ago

I think it is okay to add the | quote call. I am not sure it fixes it because at least on my laptop helm seems to round the 4.10 channel integer value before calling quote. For example:

$ cat values.yaml
channel: 4.10
channelstring: "4.10"
$ cat templates/test.yaml
channel: {{ .Values.channel }}
channelquoted: {{ .Values.channel | quote }}
channelstring: {{ .Values.channelstring }}
channelstringquoted: {{ .Values.channelstring | quote }}

The above gives me the following:

$ helm template .
---
# Source: test/templates/test.yaml
channel: 4.1
channelquoted: "4.1"
channelstring: 4.10
channelstringquoted: "4.10"

channelquoted is 4.1 and not 4.10. So I suspect the only fix here is to quote it beforehand in the values files? FWIW I am using helm 3.11.0

claudiol commented 1 year ago

@mbaldessari yeah somehow I missed something in my test. I think adding the quote filter does not help here. There are two options:

Tag Description
!!bool Denotes a boolean value
!!int Denotes a integer value
!!float Denotes a floating point number
!!str Denotes a string

In our case for string we can do the following:

    example:
      name: example-sub
      namespace: example-sub
      channel: !!str 4.10

Result:

Either case above will render the following:

# Source: pattern-clustergroup/templates/core/subscriptions.yaml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: example-sub
  namespace: example-sub
spec:
  name: example-sub
  source: redhat-operators
  sourceNamespace: openshift-marketplace
  channel: "4.10"
  installPlanApproval: Automatic

@Ladanow This is something that we cannot really address in the Validated Pattern framework so you will have to address it in the values-*.yaml file.