Skip to content

Commit d633b6b

Browse files
committed
Merge branch 'sync-clusterclass'
2 parents 9498fa4 + a54fca3 commit d633b6b

40 files changed

+29911
-4
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ repos:
118118
name: License headers - Go
119119
stages: [commit]
120120
files: "(.*\\.go|go.mod)$"
121-
exclude: ^api/external/
121+
exclude: ^(api/external/|internal/test)
122122
args:
123123
- --license-filepath
124124
- hack/license-header.txt
@@ -129,7 +129,7 @@ repos:
129129
name: License headers - YAML and Makefiles
130130
stages: [commit]
131131
files: (^Makefile|\.(ya?ml|mk))$
132-
exclude: ^(pkg/handlers/.+/embedded|examples|charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses)/.+\.ya?ml|docs/static/helm/index\.yaml|charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml$
132+
exclude: ^(internal/test|pkg/handlers/.+/embedded|examples|charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses)/.+\.ya?ml|docs/static/helm/index\.yaml|charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml$
133133
args:
134134
- --license-filepath
135135
- hack/license-header.txt

api/v1alpha1/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ const (
2727
ClusterAutoscalerVariableName = "clusterAutoscaler"
2828
// ServiceLoadBalancerVariableName is the Service LoadBalancer config patch variable name.
2929
ServiceLoadBalancerVariableName = "serviceLoadBalancer"
30+
31+
// NamespaceSyncLabelKey is a label that can be applied to a namespace.
32+
//
33+
// When a namespace has a label with this key, ClusterClasses and their Templates are
34+
// copied to the namespace from a source namespace. The copies are not updated or deleted.
35+
NamespaceSyncLabelKey = "caren.nutanix.com/namespace-sync"
3036
)

charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ rules:
6161
- patch
6262
- update
6363
- watch
64+
- apiGroups:
65+
- bootstrap.cluster.x-k8s.io
66+
- controlplane.cluster.x-k8s.io
67+
- infrastructure.cluster.x-k8s.io
68+
resources:
69+
- '*'
70+
verbs:
71+
- create
72+
- get
73+
- list
74+
- watch
75+
- apiGroups:
76+
- cluster.x-k8s.io
77+
resources:
78+
- clusterclasses
79+
verbs:
80+
- create
81+
- get
82+
- list
83+
- watch
6484
- apiGroups:
6585
- cluster.x-k8s.io
6686
resources:

cmd/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ import (
2020
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2121
crsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1"
2222
ctrl "sigs.k8s.io/controller-runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
24+
"sigs.k8s.io/controller-runtime/pkg/controller"
2325
"sigs.k8s.io/controller-runtime/pkg/healthz"
2426
"sigs.k8s.io/controller-runtime/pkg/manager"
2527
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2628

2729
caaphv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
30+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
2831
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
2932
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/server"
33+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/controllers/namespacesync"
3034
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws"
3135
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker"
3236
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic"
@@ -95,6 +99,8 @@ func main() {
9599
// It allows to specify configuration under a single variable.
96100
genericMetaHandlers := generic.New()
97101

102+
namespacesyncOptions := namespacesync.Options{}
103+
98104
// Initialize and parse command line flags.
99105
logs.AddFlags(pflag.CommandLine, logs.SkipLoggingConfigurationFlags())
100106
logsv1.AddFlags(logOptions, pflag.CommandLine)
@@ -104,6 +110,7 @@ func main() {
104110
awsMetaHandlers.AddFlags(pflag.CommandLine)
105111
dockerMetaHandlers.AddFlags(pflag.CommandLine)
106112
nutanixMetaHandlers.AddFlags(pflag.CommandLine)
113+
namespacesyncOptions.AddFlags(pflag.CommandLine)
107114
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
108115
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
109116
pflag.Parse()
@@ -141,6 +148,32 @@ func main() {
141148
os.Exit(1)
142149
}
143150

151+
unstructuredCachingClient, err := client.New(mgr.GetConfig(), client.Options{
152+
HTTPClient: mgr.GetHTTPClient(),
153+
Cache: &client.CacheOptions{
154+
Reader: mgr.GetCache(),
155+
Unstructured: true,
156+
},
157+
})
158+
if err != nil {
159+
setupLog.Error(err, "unable to create unstructured caching client")
160+
os.Exit(1)
161+
}
162+
163+
if err := (&namespacesync.Reconciler{
164+
Client: mgr.GetClient(),
165+
UnstructuredCachingClient: unstructuredCachingClient,
166+
SourceClusterClassNamespace: namespacesyncOptions.SourceNamespace,
167+
TargetNamespaceFilter: namespacesync.NamespaceHasLabelKey(v1alpha1.NamespaceSyncLabelKey),
168+
}).SetupWithManager(
169+
signalCtx,
170+
mgr,
171+
controller.Options{MaxConcurrentReconciles: namespacesyncOptions.Concurrency},
172+
); err != nil {
173+
setupLog.Error(err, "unable to create controller", "controller", "namespacesync.Reconciler")
174+
os.Exit(1)
175+
}
176+
144177
if err := mgr.Start(signalCtx); err != nil {
145178
setupLog.Error(err, "unable to start controller manager")
146179
os.Exit(1)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ replace (
1515
require (
1616
github.com/blang/semver/v4 v4.0.0
1717
github.com/go-logr/logr v1.4.2
18+
github.com/gobuffalo/flect v1.0.2
1819
github.com/google/go-cmp v0.6.0
1920
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api v0.0.0-00010101000000-000000000000
2021
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0
2122
github.com/nutanix-cloud-native/prism-go-client v0.4.0
2223
github.com/onsi/ginkgo/v2 v2.19.0
2324
github.com/onsi/gomega v1.33.1
25+
github.com/pkg/errors v0.9.1
2426
github.com/spf13/pflag v1.0.5
2527
github.com/stretchr/testify v1.9.0
2628
gopkg.in/yaml.v2 v2.4.0
@@ -71,7 +73,6 @@ require (
7173
github.com/go-openapi/jsonreference v0.20.2 // indirect
7274
github.com/go-openapi/swag v0.22.3 // indirect
7375
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
74-
github.com/gobuffalo/flect v1.0.2 // indirect
7576
github.com/gogo/protobuf v1.3.2 // indirect
7677
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
7778
github.com/golang/protobuf v1.5.4 // indirect
@@ -105,7 +106,6 @@ require (
105106
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
106107
github.com/pelletier/go-toml v1.9.5 // indirect
107108
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
108-
github.com/pkg/errors v0.9.1 // indirect
109109
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
110110
github.com/prometheus/client_golang v1.18.0 // indirect
111111
github.com/prometheus/client_model v0.5.0 // indirect

internal/test/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
Copyright 2024 Nutanix. All rights reserved.
3+
SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
# Test Framework
7+
8+
## Origin
9+
10+
This directory is a copy, with modifications, of the [upstream test
11+
package](https://github.com/kubernetes-sigs/cluster-api/tree/v1.7.2/internal/test).
12+
13+
## Purpose
14+
15+
The namespacesync controller reads and writes Templates of various types. The
16+
upstream test package creates "generic" Template types and CRDs. This allows us
17+
to test the controller using envtest, with real types and CRDs.

0 commit comments

Comments
 (0)