knative / operator

Combined operator for Knative.
Apache License 2.0
179 stars 98 forks source link

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

Open gabbler97 opened 5 months ago

gabbler97 commented 5 months ago

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

github-actions[bot] commented 2 months ago

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.

houshengbo commented 1 month ago

@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?

gabbler97 commented 1 month ago

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 commented 1 month ago

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.