Skip to content

Commit

Permalink
Merge branch 'sync-clusterclass'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlipovetsky committed Jun 17, 2024
2 parents 9498fa4 + a54fca3 commit d633b6b
Show file tree
Hide file tree
Showing 40 changed files with 29,911 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ repos:
name: License headers - Go
stages: [commit]
files: "(.*\\.go|go.mod)$"
exclude: ^api/external/
exclude: ^(api/external/|internal/test)
args:
- --license-filepath
- hack/license-header.txt
Expand All @@ -129,7 +129,7 @@ repos:
name: License headers - YAML and Makefiles
stages: [commit]
files: (^Makefile|\.(ya?ml|mk))$
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$
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$
args:
- --license-filepath
- hack/license-header.txt
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ const (
ClusterAutoscalerVariableName = "clusterAutoscaler"
// ServiceLoadBalancerVariableName is the Service LoadBalancer config patch variable name.
ServiceLoadBalancerVariableName = "serviceLoadBalancer"

// NamespaceSyncLabelKey is a label that can be applied to a namespace.
//
// When a namespace has a label with this key, ClusterClasses and their Templates are
// copied to the namespace from a source namespace. The copies are not updated or deleted.
NamespaceSyncLabelKey = "caren.nutanix.com/namespace-sync"
)
20 changes: 20 additions & 0 deletions charts/cluster-api-runtime-extensions-nutanix/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ rules:
- patch
- update
- watch
- apiGroups:
- bootstrap.cluster.x-k8s.io
- controlplane.cluster.x-k8s.io
- infrastructure.cluster.x-k8s.io
resources:
- '*'
verbs:
- create
- get
- list
- watch
- apiGroups:
- cluster.x-k8s.io
resources:
- clusterclasses
verbs:
- create
- get
- list
- watch
- apiGroups:
- cluster.x-k8s.io
resources:
Expand Down
33 changes: 33 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
crsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

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

namespacesyncOptions := namespacesync.Options{}

// Initialize and parse command line flags.
logs.AddFlags(pflag.CommandLine, logs.SkipLoggingConfigurationFlags())
logsv1.AddFlags(logOptions, pflag.CommandLine)
Expand All @@ -104,6 +110,7 @@ func main() {
awsMetaHandlers.AddFlags(pflag.CommandLine)
dockerMetaHandlers.AddFlags(pflag.CommandLine)
nutanixMetaHandlers.AddFlags(pflag.CommandLine)
namespacesyncOptions.AddFlags(pflag.CommandLine)
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
Expand Down Expand Up @@ -141,6 +148,32 @@ func main() {
os.Exit(1)
}

unstructuredCachingClient, err := client.New(mgr.GetConfig(), client.Options{
HTTPClient: mgr.GetHTTPClient(),
Cache: &client.CacheOptions{
Reader: mgr.GetCache(),
Unstructured: true,
},
})
if err != nil {
setupLog.Error(err, "unable to create unstructured caching client")
os.Exit(1)
}

if err := (&namespacesync.Reconciler{
Client: mgr.GetClient(),
UnstructuredCachingClient: unstructuredCachingClient,
SourceClusterClassNamespace: namespacesyncOptions.SourceNamespace,
TargetNamespaceFilter: namespacesync.NamespaceHasLabelKey(v1alpha1.NamespaceSyncLabelKey),
}).SetupWithManager(
signalCtx,
mgr,
controller.Options{MaxConcurrentReconciles: namespacesyncOptions.Concurrency},
); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "namespacesync.Reconciler")
os.Exit(1)
}

if err := mgr.Start(signalCtx); err != nil {
setupLog.Error(err, "unable to start controller manager")
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ replace (
require (
github.com/blang/semver/v4 v4.0.0
github.com/go-logr/logr v1.4.2
github.com/gobuffalo/flect v1.0.2
github.com/google/go-cmp v0.6.0
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api v0.0.0-00010101000000-000000000000
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0
github.com/nutanix-cloud-native/prism-go-client v0.4.0
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/pkg/errors v0.9.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -71,7 +73,6 @@ require (
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand Down Expand Up @@ -105,7 +106,6 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand Down
17 changes: 17 additions & 0 deletions internal/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
Copyright 2024 Nutanix. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->

# Test Framework

## Origin

This directory is a copy, with modifications, of the [upstream test
package](https://github.com/kubernetes-sigs/cluster-api/tree/v1.7.2/internal/test).

## Purpose

The namespacesync controller reads and writes Templates of various types. The
upstream test package creates "generic" Template types and CRDs. This allows us
to test the controller using envtest, with real types and CRDs.
Loading

0 comments on commit d633b6b

Please sign in to comment.