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

Helm date format error #667

Closed
lblackstone opened this issue Jul 30, 2019 · 10 comments · Fixed by #690
Closed

Helm date format error #667

lblackstone opened this issue Jul 30, 2019 · 10 comments · Fixed by #690
Assignees
Labels
area/helm kind/bug Some behavior is incorrect or out of spec
Milestone

Comments

@lblackstone
Copy link
Member

lblackstone commented Jul 30, 2019

I came across a chart that includes a .tpl file which apparently is used to define some common values for the chart. I get the following errors when I try to install the chart:

  kubernetes:core:Service (default/keda-keda-edge):
    error: Plan apply failed: resource keda-keda-edge/%!s(MISSING) was not successfully created by the Kubernetes API server default: Service "keda-keda-edge" is invalid: metadata.labels: Invalid value: "2019-07-30T00:00:00.000Z": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')

  pulumi:pulumi:Stack (pulumi-k8s-test-pulumi-k8s-test-dev):
    error: update failed

  kubernetes:core:ServiceAccount (default/keda-serviceaccount):
    error: Plan apply failed: resource keda-serviceaccount/%!s(MISSING) was not successfully created by the Kubernetes API server default: ServiceAccount "keda-serviceaccount" is invalid: metadata.labels: Invalid value: "2019-07-30T00:00:00.000Z": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')

  kubernetes:rbac.authorization.k8s.io:ClusterRoleBinding (default/keda-keda-edge):
    error: Plan apply failed: resource keda-keda-edge/%!s(MISSING) was not successfully created by the Kubernetes API server default: ClusterRoleBinding.rbac.authorization.k8s.io "keda-keda-edge" is invalid: metadata.labels: Invalid value: "2019-07-30T00:00:00.000Z": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')

Here's the code I used to create the chart:

const keda = new k8s.helm.v2.Chart("keda", {
        repo: "kedacore",
        chart: "keda-edge",
        version: "0.0.1-2019.07.24.21.37.42-8ffd9a3",
        values: {
            logLevel: "debug",
        },
});
@lblackstone
Copy link
Member Author

lblackstone commented Jul 30, 2019

Hmm, after some further testing, it seems that helm template works with this chart, so it's likely a problem with our Helm support in the Node SDK.

Here's an example of the Service object generated by helm template:

# Source: keda-edge/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: keda-edge
    chart: keda-edge-0.0.1-2019.07.24.21.37.42-8ffd9a3
    release: keda-edge
    date: 2019-07-30
  name: keda-edge
  namespace: default
spec:
  ports:
  - name: https
    port: 443
    targetPort: 6443
  - name: http
    port: 80
    targetPort: 8080
  selector:
    name: keda-edge
    instance: keda-edge-instance

The date format was different in our error message, so that's probably the culprit:

2019-07-30

vs

2019-07-30T00:00:00.000Z

The date was generated with the following line in the chart:
https://github.com/kedacore/keda/blob/8ffd9a3e236e39eafcf0ec85616d6111783e0273/chart/keda/templates/_helpers.tpl#L49

Edit: Verified that the extended date format fails to validate against the regex, so that's the source of the failure. Not sure why the date is being generated in that format.

@lblackstone lblackstone changed the title Helm .tpl files unsupported Helm date format error Jul 30, 2019
@lblackstone lblackstone added area/helm feature/q3 kind/bug Some behavior is incorrect or out of spec labels Jul 30, 2019
@mikhailshilkov
Copy link
Member

For context, I was trying to create an example of KEDA with Pulumi by porting this Terraform example

@lblackstone
Copy link
Member Author

cc @pgavlin @hausdorff

Do you know what would cause the date to be generated in that format?

@lukehoban
Copy link
Member

it’s likely a problem with the Helm support on our Node SDK

We just shell out to helm template. Does the exact same command line we pass produce something different when you run it manually?

https://github.com/pulumi/pulumi-kubernetes/blob/master/sdk/nodejs/helm/v2/helm.ts#L175

@lblackstone
Copy link
Member Author

@lukehoban Yes, when I ran it manually, the date format was 2019-07-30

@lukehoban
Copy link
Member

Oh YAML...

> JSON.stringify(require('js-yaml').safeLoad(`date: 2019-07-30`))
'{"date":"2019-07-30T00:00:00.000Z"}'

@lukehoban
Copy link
Member

Sounds like we need to provide the same "Schema" as Kubernetes will use to parse this YAML. Do we know what that is?

nodeca/js-yaml#161 (comment)

@lukehoban
Copy link
Member

I think we need to set schema: CORE_SCHEMA to match Kubernetes.

> JSON.stringify(require('js-yaml').safeLoad(`date: 2019-07-30`, {json: true, schema: require('js-yaml').CORE_SCHEMA}))
'{"date":"2019-07-30"}'

@lukehoban
Copy link
Member

Kubernetes ultimately bottoms out on using gopkg.in/yaml.v2.

https://github.com/kubernetes-sigs/yaml/blob/v1.1.0/yaml.go#L49

That package is not super-clear on the precise profile of YAML that it uses for parsing, or even what specification it is aiming to be compatible with.

lukehoban added a commit that referenced this issue Jul 30, 2019
@lukehoban lukehoban self-assigned this Jul 30, 2019
@lukehoban lukehoban added this to the 0.26 milestone Jul 30, 2019
@mikhailshilkov
Copy link
Member

Thanks Luke, I've been grinding jsyaml to find the reason.

I think we need to set schema: CORE_SCHEMA to match Kubernetes.

> JSON.stringify(require('js-yaml').safeLoad(`date: 2019-07-30`, {json: true, schema: require('js-yaml').CORE_SCHEMA}))
'{"date":"2019-07-30"}'

This fixes the problem! I have the chart deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/helm kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants