bitnami / kube-libsonnet

Bitnami's jsonnet library for building Kubernetes manifests
https://bitnami.com
Apache License 2.0
174 stars 50 forks source link

Invalid ingress definitions due to missing `pathType` field. #65

Closed juan131 closed 3 years ago

juan131 commented 3 years ago

Context

In K8s 1.18 a new field named pathType was introduced in the Ingress API. This field is mandatory on k8s > v1.19. Find more info below::

Description

I have a solution running on a cluster that was recently moved to 1.19 managed with kubecfg and using this library. I tried today to update my solution, and I faced the error below while upgrading:

Error updating ingresses {{NAMESPASCE}}.{{INGRESS_NAME}}: Ingress.extensions "{{INGRESS_NAME}}" is invalid: spec.rules[0].http.paths[0].pathType: Required value: pathType must be specified

Am I missing something or do we need to update this library to include the new field?

Extra information

This is sth we solved in the Bitnami Helm catalog by implementing a macro that allows us to detect the k8s version and decide whether to include this parameter or not, see:

jbianquetti-nami commented 3 years ago

Let me take a look at this. I'll keep you posted

jbianquetti-nami commented 3 years ago

@juan131

This commit is supposed to handle this use case. https://github.com/bitnami-labs/kube-libsonnet/commit/20bf70d8d24b3a50baaae8f951dcbc62a66b464f

Did you update the kube-libsonnet library to the latest version?

juan131 commented 3 years ago

Yes, I have the latest changes @jbianquetti-nami

Do you know If I need to enable anything? This is how I'm defining the Ingress rule:

  ingress: bitnami.Ingress($.app_name) {
    host:: $.hostname,
    metadata+: {
      namespace: $.namespace,
      labels+: { app: labels.app, name: $.app_name },
      annotations+: {
        "nginx.ingress.kubernetes.io/whitelist-source-range": "0.0.0.0/0",
      },
    },
    paths: [
      { path: "/", backend: $.service.name_port },
    ],
  },
dbarranco commented 3 years ago

Hey @juan131, thanks for creating this issue.

I have been reviewing your Ingress code snippet and the bitnami.libsonnet library and found-out that the issue is related to your paths definition.

The paths code snippet:

    paths: [
      { path: "/", backend: $.service.name_port },
    ],

overrides this one:

    paths:: [
      {
        path: "/",
        backend: ing.target_svc.name_port,
        pathType: "ImplementationSpecific",
      },
    ],

So the pathType annotation you're looking for is not added. Your Ingress snippet should look like this:

ingress: bitnami.Ingress($.app_name) {
    host:: $.hostname,
    target_svc:: $.service,

    metadata+: {
      namespace: $.namespace,
      labels+: { app: labels.app, name: $.app_name },
      annotations+: {
        "nginx.ingress.kubernetes.io/whitelist-source-range": "0.0.0.0/0",
      },
    },
  },

I'm closing this issue, as the feature you're missing has already been added to the library in #63