Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trailing zero is removed from channel in subscription #295

Open
Ladanow opened this issue Apr 14, 2023 · 3 comments
Open

trailing zero is removed from channel in subscription #295

Ladanow opened this issue Apr 14, 2023 · 3 comments

Comments

@Ladanow
Copy link

Ladanow commented Apr 14, 2023

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
Copy link
Contributor

claudiol commented Apr 14, 2023

@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
Copy link
Contributor

mbaldessari commented Apr 16, 2023

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
Copy link
Contributor

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

  • Use the common tags in yaml
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
  • Just use the single (') or double quote (")
    example:
      name: example-sub
      namespace: example-sub
      channel: '4.10'

or

    example:
      name: example-sub
      namespace: example-sub
      channel: "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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants