Skip to content

Commit e871038

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

12 files changed

Lines changed: 529 additions & 34 deletions

File tree

cmd/operator/main.go

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

1919
import (
20+
"flag"
21+
22+
"knative.dev/operator/pkg/reconciler/common"
2023
"knative.dev/operator/pkg/reconciler/knativeeventing"
2124
"knative.dev/operator/pkg/reconciler/knativeserving"
2225
kubefilteredfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
@@ -25,6 +28,11 @@ import (
2528
)
2629

2730
func main() {
31+
flag.StringVar(&common.CredentialProvidersConfigPath,
32+
"credential-providers-config", "",
33+
"Path to the credential providers config file for "+
34+
"Cluster Inventory API multi-cluster support")
35+
2836
ctx := signals.NewContext()
2937
ctx = kubefilteredfactory.WithSelectors(ctx,
3038
knativeserving.Selector,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ spec:
6666
- URL
6767
type: object
6868
type: array
69+
clusterProfileRef:
70+
description: |-
71+
ClusterProfileRef is an optional reference to a ClusterProfile resource
72+
(multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
73+
the component on the remote cluster described by the referenced
74+
ClusterProfile instead of the local cluster.
75+
properties:
76+
name:
77+
description: Name is the name of the ClusterProfile resource.
78+
type: string
79+
namespace:
80+
description: Namespace is the namespace of the ClusterProfile
81+
resource.
82+
type: string
83+
required:
84+
- name
85+
- namespace
86+
type: object
6987
config:
7088
additionalProperties:
7189
additionalProperties:

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ spec:
6666
- URL
6767
type: object
6868
type: array
69+
clusterProfileRef:
70+
description: |-
71+
ClusterProfileRef is an optional reference to a ClusterProfile resource
72+
(multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
73+
the component on the remote cluster described by the referenced
74+
ClusterProfile instead of the local cluster.
75+
properties:
76+
name:
77+
description: Name is the name of the ClusterProfile resource.
78+
type: string
79+
namespace:
80+
description: Namespace is the namespace of the ClusterProfile
81+
resource.
82+
type: string
83+
required:
84+
- name
85+
- namespace
86+
type: object
6987
config:
7088
additionalProperties:
7189
additionalProperties:

config/rbac/role.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ rules:
253253
- pods
254254
verbs:
255255
- get
256+
# Multi-cluster support: read ClusterProfile resources.
257+
# Requires the Cluster Inventory API CRD (multicluster.x-k8s.io).
258+
# These permissions are harmless if the CRD is not installed.
259+
- apiGroups:
260+
- multicluster.x-k8s.io
261+
resources:
262+
- clusterprofiles
263+
verbs:
264+
- get
265+
- list
266+
- watch
256267
---
257268
kind: ClusterRole
258269
apiVersion: rbac.authorization.k8s.io/v1
@@ -644,3 +655,14 @@ rules:
644655
- list
645656
- get
646657
- watch
658+
# Multi-cluster support: read ClusterProfile resources.
659+
# Requires the Cluster Inventory API CRD (multicluster.x-k8s.io).
660+
# These permissions are harmless if the CRD is not installed.
661+
- apiGroups:
662+
- multicluster.x-k8s.io
663+
resources:
664+
- clusterprofiles
665+
verbs:
666+
- get
667+
- list
668+
- watch

pkg/apis/operator/base/common.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type KComponentSpec interface {
7979

8080
// GetPodDisruptionBudgetOverride gets the PodDisruptionBudget configurations to override.
8181
GetPodDisruptionBudgetOverride() []PodDisruptionBudgetOverride
82+
83+
// GetClusterProfileRef returns a reference to a ClusterProfile for multi-cluster deployment.
84+
GetClusterProfileRef() *ClusterProfileReference
8285
}
8386

8487
// KComponentStatus is a common interface for status mutations of all known types.
@@ -176,6 +179,13 @@ type CommonSpec struct {
176179
// PodDisruptionBudgetOverride overrides PodDisruptionBudget configurations via minAvailable.
177180
// +optional
178181
PodDisruptionBudgetOverride []PodDisruptionBudgetOverride `json:"podDisruptionBudgets,omitempty"`
182+
183+
// ClusterProfileRef is an optional reference to a ClusterProfile resource
184+
// (multicluster.x-k8s.io/v1alpha1). When set, the operator reconciles
185+
// the component on the remote cluster described by the referenced
186+
// ClusterProfile instead of the local cluster.
187+
// +optional
188+
ClusterProfileRef *ClusterProfileReference `json:"clusterProfileRef,omitempty"`
179189
}
180190

181191
// GetConfig implements KComponentSpec.
@@ -233,6 +243,11 @@ func (c *CommonSpec) GetPodDisruptionBudgetOverride() []PodDisruptionBudgetOverr
233243
return c.PodDisruptionBudgetOverride
234244
}
235245

246+
// GetClusterProfileRef implements KComponentSpec.
247+
func (c *CommonSpec) GetClusterProfileRef() *ClusterProfileReference {
248+
return c.ClusterProfileRef
249+
}
250+
236251
// ConfigMapData is a nested map of maps representing all upstream ConfigMaps. The first
237252
// level key is the key to the ConfigMap itself (i.e. "logging") while the second level
238253
// is the data to be filled into the respective ConfigMap.
@@ -431,3 +446,14 @@ type CustomCerts struct {
431446
// The name of the ConfigMap or Secret
432447
Name string `json:"name"`
433448
}
449+
450+
// ClusterProfileReference identifies a ClusterProfile resource from the
451+
// Cluster Inventory API (multicluster.x-k8s.io/v1alpha1).
452+
// When set, the operator deploys resources to the remote cluster described by
453+
// this ClusterProfile instead of the local cluster.
454+
type ClusterProfileReference struct {
455+
// Name is the name of the ClusterProfile resource.
456+
Name string `json:"name"`
457+
// Namespace is the namespace of the ClusterProfile resource.
458+
Namespace string `json:"namespace"`
459+
}

pkg/apis/operator/base/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)