operator icon indicating copy to clipboard operation
operator copied to clipboard

Ability to mount configmaps to override config in knative-serving and knative-eventing resources

Open gabbler97 opened this issue 2 years ago • 4 comments

Problem I have followed this page to override the default configmaps instead of modifying them manually. https://vincenthou.medium.com/how-to-customize-the-manifests-for-knative-operator-with-a-local-volume-c576b592d9d7 The problem is the following: I could not attach configmaps to the knative-operator through helm chart so I had to modify the Chart myself. It is working now, but I would have to do this at every new version.

kubectl get deploy  knative-operator -o yaml
...
        volumeMounts:
        - mountPath: /cm-ingress-gateway
          name: cm-ingress-gateway
        - mountPath: /cm-config-domain
          name: cm-config-domain
        - mountPath: /cm-config-network
          name: cm-config-network
      serviceAccount: knative-operator
      serviceAccountName: knative-operator
      volumes:
      - configMap:
          name: cm-ingress-gateway
        name: cm-ingress-gateway
      - configMap:
          name: cm-config-network
        name: cm-config-network
      - configMap:
          name: cm-config-domain
        name: cm-config-domain
...

Exit Criteria I can use the extra configmaps like this

apiVersion: operator.knative.dev/v1beta1
kind: KnativeServing
metadata:
  name: knative-serving
  namespace: knative-serving
spec:
  config:
    istio:
      local-gateway.knative-serving.knative-local-gateway: knative-local-gateway.istio-system.svc.cluster.local
  additionalManifests:
    - URL: /cm-ingress-gateway
    - URL: /cm-config-domain
    - URL: /cm-config-network
  ingress:
    istio:
      enabled: true

Time Estimate (optional): 1-2 days

gabbler97 avatar Jan 24 '24 08:01 gabbler97

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Apr 24 '24 01:04 github-actions[bot]

@gabbler97 The content in the blog was using a hacky way. I am not sure how you change the helm chart to make it work. Would you mind sharing your approach?

houshengbo avatar May 21 '24 13:05 houshengbo

Hello @houshengbo! Sure. in values.yaml

knative_operator:
  knative_operator:
    image: gcr.io/knative-releases/knative.dev/operator/cmd/operator
    tag: v1.13.1
    customCm: # Added this
      enabled: false # And this

In templates/operator.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: knative-operator
  namespace: "{{ .Release.Namespace }}"
  labels:
    app.kubernetes.io/name: knative-operator
    app.kubernetes.io/version: "{{ .Chart.Version }}"
spec:
  replicas: 1
  selector:
    matchLabels:
      name: knative-operator
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        name: knative-operator
        app.kubernetes.io/name: knative-operator
        app.kubernetes.io/version: "{{ .Chart.Version }}"
    spec:
      serviceAccountName: knative-operator
      {{ if .Values.knative_operator.knative_operator.customCm.enabled }}
      volumes:
      - configMap:
          name: cm-config-network
        name: cm-config-network
      - configMap:
          name: cm-config-domain
        name: cm-config-domain
      {{ end }}
      containers:
        - name: knative-operator
          image: "{{ .Values.knative_operator.knative_operator.image }}:{{ .Values.knative_operator.knative_operator.tag }}"
          imagePullPolicy: IfNotPresent
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: SYSTEM_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: METRICS_DOMAIN
              value: knative.dev/operator
            - name: CONFIG_LOGGING_NAME
              value: config-logging
            - name: CONFIG_OBSERVABILITY_NAME
              value: config-observability
            - name: KUBERNETES_MIN_VERSION
              value: "{{ .Values.knative_operator.kubernetes_min_version }}"
          ports:
            - name: metrics
              containerPort: 9090
           # This block was added
          {{ if .Values.knative_operator.knative_operator.customCm.enabled }}
          volumeMounts:
          - mountPath: /cm-config-domain
            name: cm-config-domain
          - mountPath: /cm-config-network
            name: cm-config-network
          {{ end }}

Finally in knative serving resource

spec:
  additionalManifests:
    - URL: /cm-ingress-gateway
    - URL: /cm-config-domain
    - URL: /cm-config-network

gabbler97 avatar May 21 '24 13:05 gabbler97

There are a lot of configmaps but this is a simple example how I would use it

domainconfig:
 ovverrideenabled: <bool>
 overrideconfigcontent: |
   multilinecontent
   multilinecontent

And the the content of this would go under a configmap k get cm config-domain -o yaml

apiVersion: v1
data:
   multilinecontent
   multilinecontent
kind: ConfigMap

And you would create that custom config cm only when override is enabled. It is just an idea of course.

gabbler97 avatar May 21 '24 13:05 gabbler97

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Aug 20 '24 01:08 github-actions[bot]