Skip to content

Commit b4b0b37

Browse files
committed
add multi-cluster deployment support via Cluster Inventory API
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
1 parent 786194b commit b4b0b37

196 files changed

Lines changed: 13839 additions & 4071 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/operator/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
// Register --clusterprofile-provider-file before sharedmain parses flags.
21+
_ "knative.dev/operator/pkg/reconciler/common"
2022
"knative.dev/operator/pkg/reconciler/knativeeventing"
2123
"knative.dev/operator/pkg/reconciler/knativeserving"
2224
kubefilteredfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"

config/charts/knative-operator/templates/crds/knativeeventings.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ spec:
3232
singular: knativeeventing
3333
scope: Namespaced
3434
versions:
35-
- name: v1beta1
35+
- additionalPrinterColumns:
36+
- jsonPath: .spec.clusterProfileRef.name
37+
name: Target Cluster
38+
priority: 1
39+
type: string
40+
name: v1beta1
3641
schema:
3742
openAPIV3Schema:
3843
description: KnativeEventing is the Schema for the eventings API
@@ -69,6 +74,25 @@ spec:
6974
- URL
7075
type: object
7176
type: array
77+
clusterProfileRef:
78+
description: |-
79+
ClusterProfileRef is an optional reference to a ClusterProfile resource
80+
(multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
81+
the component on the remote cluster described by the referenced
82+
ClusterProfile instead of the local cluster.
83+
properties:
84+
name:
85+
description: Name is the name of the ClusterProfile resource.
86+
minLength: 1
87+
type: string
88+
namespace:
89+
description: Namespace is the namespace of the ClusterProfile resource.
90+
minLength: 1
91+
type: string
92+
required:
93+
- name
94+
- namespace
95+
type: object
7296
config:
7397
additionalProperties:
7498
additionalProperties:

config/charts/knative-operator/templates/crds/knativeservings.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ spec:
3232
singular: knativeserving
3333
scope: Namespaced
3434
versions:
35-
- name: v1beta1
35+
- additionalPrinterColumns:
36+
- jsonPath: .spec.clusterProfileRef.name
37+
name: Target Cluster
38+
priority: 1
39+
type: string
40+
name: v1beta1
3641
schema:
3742
openAPIV3Schema:
3843
description: KnativeServing is the Schema for the knativeservings API
@@ -69,6 +74,25 @@ spec:
6974
- URL
7075
type: object
7176
type: array
77+
clusterProfileRef:
78+
description: |-
79+
ClusterProfileRef is an optional reference to a ClusterProfile resource
80+
(multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
81+
the component on the remote cluster described by the referenced
82+
ClusterProfile instead of the local cluster.
83+
properties:
84+
name:
85+
description: Name is the name of the ClusterProfile resource.
86+
minLength: 1
87+
type: string
88+
namespace:
89+
description: Namespace is the namespace of the ClusterProfile resource.
90+
minLength: 1
91+
type: string
92+
required:
93+
- name
94+
- namespace
95+
type: object
7296
config:
7397
additionalProperties:
7498
additionalProperties:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2025 The Knative Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
{{- $mc := .Values.knative_operator.multicluster | default dict }}
16+
{{- if $mc.enabled }}
17+
{{- $mountPaths := list }}
18+
{{- range ($mc.plugins | default (list)) }}
19+
{{- $mountPaths = append $mountPaths .mountPath }}
20+
{{- end }}
21+
{{- $cfg := $mc.accessProvidersConfig | default dict }}
22+
{{- range ($cfg.providers | default (list)) }}
23+
{{- $cmd := (.execConfig | default dict).command | default "" }}
24+
{{- if $cmd }}
25+
{{- $cmdDir := dir $cmd }}
26+
{{- if not (has $cmdDir $mountPaths) }}
27+
{{- fail (printf "multicluster validation error: provider %q command %q has parent dir %q which does not match any plugins[].mountPath (have %v); execConfig.command parent directory must equal a plugin mountPath" .name $cmd $cmdDir $mountPaths) }}
28+
{{- end }}
29+
{{- end }}
30+
{{- end }}
31+
apiVersion: v1
32+
kind: ConfigMap
33+
metadata:
34+
name: clusterprofile-provider-file
35+
namespace: "{{ .Release.Namespace }}"
36+
labels:
37+
app.kubernetes.io/name: knative-operator
38+
app.kubernetes.io/version: "{{ .Chart.Version }}"
39+
data:
40+
config.json: {{ $mc.accessProvidersConfig | default dict | mustToJson | quote }}
41+
{{- end }}

config/charts/knative-operator/templates/operator.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,5 +855,30 @@ spec:
855855
ports:
856856
- name: metrics
857857
containerPort: 9090
858+
{{- $mc := .Values.knative_operator.multicluster | default dict }}
859+
{{- if $mc.enabled }}
860+
args:
861+
- --clusterprofile-provider-file=/etc/cluster-inventory/config.json
862+
volumeMounts:
863+
- name: cred-config
864+
mountPath: /etc/cluster-inventory
865+
readOnly: true
866+
{{- range ($mc.plugins | default list) }}
867+
- name: {{ .name }}
868+
mountPath: {{ .mountPath }}
869+
readOnly: true
870+
{{- end }}
871+
{{- end }}
872+
{{- if $mc.enabled }}
873+
volumes:
874+
- name: cred-config
875+
configMap:
876+
name: clusterprofile-provider-file
877+
{{- range ($mc.plugins | default list) }}
878+
- name: {{ .name }}
879+
image:
880+
reference: {{ .image }}
881+
{{- end }}
882+
{{- end }}
858883

859884
---

config/charts/knative-operator/templates/rbac/eventing-operator-role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,12 @@ rules:
401401
- list
402402
- get
403403
- watch
404+
# for multicluster support
405+
- apiGroups:
406+
- multicluster.x-k8s.io
407+
resources:
408+
- clusterprofiles
409+
verbs:
410+
- get
411+
- list
412+
- watch

config/charts/knative-operator/templates/rbac/serving-operator-role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ rules:
252252
- pods
253253
verbs:
254254
- get
255+
# for multicluster support
256+
- apiGroups:
257+
- multicluster.x-k8s.io
258+
resources:
259+
- clusterprofiles
260+
verbs:
261+
- get
262+
- list
263+
- watch
255264
# Copyright 2020 The Knative Authors
256265
#
257266
# Licensed under the Apache License, Version 2.0 (the "License");

config/charts/knative-operator/values.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
knative_operator:
2+
# Multi-cluster (Cluster Inventory API): when enabled, the chart mounts
3+
# access provider config and optional plugin images, and sets
4+
# --clusterprofile-provider-file on the operator. ClusterProfile.status
5+
# accessProviders are not managed by this chart.
6+
multicluster:
7+
enabled: false
8+
accessProvidersConfig: {}
9+
# plugins[] uses the Kubernetes "image" volume type
10+
plugins: []
11+
# accessProvidersConfig:
12+
# providers:
13+
# - name: token-secretreader
14+
# execConfig:
15+
# apiVersion: client.authentication.k8s.io/v1
16+
# command: /credential-plugins/token-secretreader/kubeconfig-secretreader-plugin
17+
# provideClusterInfo: true
18+
# plugins:
19+
# - name: token-secretreader
20+
# image: ghcr.io/example/plugin:v1.0.0
21+
# mountPath: /credential-plugins/token-secretreader
222
knative_operator:
323
image: gcr.io/knative-releases/knative.dev/operator/cmd/operator
424
tag: {{ tag }}

config/crd/bases/operator.knative.dev_knativeeventings.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ spec:
2828
singular: knativeeventing
2929
scope: Namespaced
3030
versions:
31-
- name: v1beta1
31+
- additionalPrinterColumns:
32+
- jsonPath: .spec.clusterProfileRef.name
33+
name: Target Cluster
34+
priority: 1
35+
type: string
36+
name: v1beta1
3237
schema:
3338
openAPIV3Schema:
3439
description: KnativeEventing is the Schema for the eventings API
@@ -66,6 +71,26 @@ spec:
6671
- URL
6772
type: object
6873
type: array
74+
clusterProfileRef:
75+
description: |-
76+
ClusterProfileRef is an optional reference to a ClusterProfile resource
77+
(multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
78+
the component on the remote cluster described by the referenced
79+
ClusterProfile instead of the local cluster.
80+
properties:
81+
name:
82+
description: Name is the name of the ClusterProfile resource.
83+
minLength: 1
84+
type: string
85+
namespace:
86+
description: Namespace is the namespace of the ClusterProfile
87+
resource.
88+
minLength: 1
89+
type: string
90+
required:
91+
- name
92+
- namespace
93+
type: object
6994
config:
7095
additionalProperties:
7196
additionalProperties:

config/crd/bases/operator.knative.dev_knativeservings.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ spec:
2828
singular: knativeserving
2929
scope: Namespaced
3030
versions:
31-
- name: v1beta1
31+
- additionalPrinterColumns:
32+
- jsonPath: .spec.clusterProfileRef.name
33+
name: Target Cluster
34+
priority: 1
35+
type: string
36+
name: v1beta1
3237
schema:
3338
openAPIV3Schema:
3439
description: KnativeServing is the Schema for the knativeservings API
@@ -66,6 +71,26 @@ spec:
6671
- URL
6772
type: object
6873
type: array
74+
clusterProfileRef:
75+
description: |-
76+
ClusterProfileRef is an optional reference to a ClusterProfile resource
77+
(multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
78+
the component on the remote cluster described by the referenced
79+
ClusterProfile instead of the local cluster.
80+
properties:
81+
name:
82+
description: Name is the name of the ClusterProfile resource.
83+
minLength: 1
84+
type: string
85+
namespace:
86+
description: Namespace is the namespace of the ClusterProfile
87+
resource.
88+
minLength: 1
89+
type: string
90+
required:
91+
- name
92+
- namespace
93+
type: object
6994
config:
7095
additionalProperties:
7196
additionalProperties:

0 commit comments

Comments
 (0)