Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
78 changes: 75 additions & 3 deletions cmd/cluster-cloud-controller-manager-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"errors"
"flag"
"os"
"time"
Expand All @@ -25,6 +26,7 @@ import (

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -39,6 +41,10 @@ import (

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
configv1client "github.com/openshift/client-go/config/clientset/versioned"
configinformers "github.com/openshift/client-go/config/informers/externalversions"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/openshift/library-go/pkg/operator/events"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/controllers"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/restmapper"
Expand Down Expand Up @@ -111,6 +117,8 @@ func main() {
LeaseDuration: leaderElectionConfig.LeaseDuration,
})

ctx := ctrl.SetupSignalHandler()

syncPeriod := 10 * time.Minute
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
Namespace: *managedNamespace,
Expand All @@ -137,15 +145,64 @@ func main() {
os.Exit(1)
}

// Setup for the feature gate accessor. This reads and monitors feature gates
// from the FeatureGate object status for the given version.
desiredVersion := controllers.GetReleaseVersion()
missingVersion := "0.0.1-snapshot"

configClient, err := configv1client.NewForConfig(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "unable to create config client")
os.Exit(1)
}
configInformers := configinformers.NewSharedInformerFactory(configClient, 10*time.Minute)

kubeClient, err := kubernetes.NewForConfig(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "unable to create kube client")
os.Exit(1)
}

controllerRef, err := events.GetControllerReferenceForCurrentPod(ctx, kubeClient, *managedNamespace, nil)
if err != nil {
klog.Warningf("unable to get owner reference (falling back to namespace): %v", err)
}

recorder := events.NewKubeRecorder(kubeClient.CoreV1().Events(*managedNamespace), "cloud-controller-manager-operator", controllerRef)
featureGateAccessor := featuregates.NewFeatureGateAccess(
desiredVersion, missingVersion,
configInformers.Config().V1().ClusterVersions(), configInformers.Config().V1().FeatureGates(),
recorder,
)

featureGateAccessor.SetChangeHandler(func(featureChange featuregates.FeatureChange) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you sure it does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been watching and reacting to the feature gate changes since we started this operator, if it couldn't handle the change (eg from nothing to TPNU) then we would have hit issues before no?

// Do nothing here. The controller watches feature gate changes and will react to them.
klog.InfoS("FeatureGates changed", "enabled", featureChange.New.Enabled, "disabled", featureChange.New.Disabled)
})

go featureGateAccessor.Run(ctx)
go configInformers.Start(ctx.Done())

select {
case <-featureGateAccessor.InitialFeatureGatesObserved():
features, _ := featureGateAccessor.CurrentFeatureGates()

enabled, disabled := getEnabledDisabledFeatures(features)
setupLog.Info("FeatureGates initialized", "enabled", enabled, "disabled", disabled)
case <-time.After(1 * time.Minute):
setupLog.Error(errors.New("timed out waiting for FeatureGate detection"), "unable to start manager")
}

if err = (&controllers.CloudOperatorReconciler{
ClusterOperatorStatusClient: controllers.ClusterOperatorStatusClient{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("cloud-controller-manager-operator"),
ReleaseVersion: controllers.GetReleaseVersion(),
ManagedNamespace: *managedNamespace,
},
Scheme: mgr.GetScheme(),
ImagesFile: *imagesFile,
Scheme: mgr.GetScheme(),
ImagesFile: *imagesFile,
FeatureGateAccess: featureGateAccessor,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ClusterOperator")
os.Exit(1)
Expand All @@ -162,8 +219,23 @@ func main() {
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}

func getEnabledDisabledFeatures(features featuregates.FeatureGate) ([]string, []string) {
var enabled []string
var disabled []string

for _, feature := range features.KnownFeatures() {
if features.Enabled(feature) {
enabled = append(enabled, string(feature))
} else {
disabled = append(disabled, string(feature))
}
}

return enabled, disabled
}
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ require (
github.com/golangci/golangci-lint v1.52.2
github.com/onsi/ginkgo/v2 v2.8.0
github.com/onsi/gomega v1.26.0
github.com/openshift/api v0.0.0-20230120195050-6ba31fa438f2
github.com/openshift/library-go v0.0.0-20230112164258-24668b1349e6
github.com/openshift/api v0.0.0-20230426193520-54a14470e5dc
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084
github.com/openshift/library-go v0.0.0-20230501171818-442d38f5a55b
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.2
Expand All @@ -30,8 +31,6 @@ require (
sigs.k8s.io/yaml v1.3.0
)

replace github.com/openshift/library-go => github.com/JoelSpeed/library-go v0.0.0-20230307115500-45b41bd4cffd

require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
4d63.com/gochecknoglobals v0.2.1 // indirect
Expand All @@ -49,6 +48,7 @@ require (
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bkielbasa/cyclop v1.2.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/blizzy78/varnamelen v0.8.0 // indirect
github.com/bombsimon/wsl/v3 v3.4.0 // indirect
github.com/breml/bidichk v0.2.4 // indirect
Expand All @@ -71,6 +71,7 @@ require (
github.com/firefart/nonamedreturns v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fzipp/gocyclo v0.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-critic/go-critic v0.7.0 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
Expand Down Expand Up @@ -157,7 +158,6 @@ require (
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.9.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -171,6 +171,7 @@ require (
github.com/quasilyte/gogrep v0.5.0 // indirect
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/ryancurrah/gomodguard v1.3.0 // indirect
github.com/ryanrolds/sqlclosecheck v0.4.0 // indirect
github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
Expand Down Expand Up @@ -226,11 +227,14 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.4.3 // indirect
k8s.io/apiserver v0.26.1 // indirect
k8s.io/kube-aggregator v0.26.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
mvdan.cc/gofumpt v0.4.0 // indirect
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/kube-storage-version-migrator v0.0.4 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Loading