Skip to content

Commit

Permalink
update to honor featuregates
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Apr 11, 2023
1 parent 9f32a9d commit 8c71879
Showing 1 changed file with 61 additions and 12 deletions.
73 changes: 61 additions & 12 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import (
"fmt"
"time"

configclient "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/v1helpers"

routemetricscontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/route-metrics"
errorpageconfigmapcontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/sync-http-error-code-configmap"
"github.com/openshift/library-go/pkg/operator/onepodpernodeccontroller"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -73,7 +78,60 @@ type Operator struct {

// New creates (but does not start) a new operator from configuration.
func New(config operatorconfig.Config, kubeConfig *rest.Config) (*Operator, error) {
ctx := context.Background()
ctx, cancelFn := context.WithCancel(ctx)
go func() {
defer cancelFn()
<-config.Stop
}()

scheme := operatorclient.GetScheme()

kubeClient, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
return nil, fmt.Errorf("failed to create kube client: %w", err)
}
namespaceInformers := informers.NewSharedInformerFactoryWithOptions(kubeClient, 24*time.Hour, informers.WithNamespace(operatorcontroller.DefaultOperandNamespace))
eventRecorder := events.NewKubeRecorder(kubeClient.CoreV1().Events(config.Namespace), "cluster-ingress-operator", &corev1.ObjectReference{
APIVersion: "apps/v1",
Kind: "Deployment",
Namespace: config.Namespace,
Name: "ingress-operator",
})

configClient, err := configclient.NewForConfig(kubeConfig)
if err != nil {
return nil, err
}
configInformers := configinformers.NewSharedInformerFactory(configClient, 10*time.Minute)
desiredVersion := config.OperatorReleaseVersion
missingVersion := statuscontroller.UnknownVersionValue

// by default, this will exit(0) the process if the featuregates ever change to a different set of values.
featureGateAccessor := featuregates.NewFeatureGateAccess(
desiredVersion, missingVersion,
configInformers.Config().V1().ClusterVersions(), configInformers.Config().V1().FeatureGates(),
eventRecorder,
)
go featureGateAccessor.Run(ctx)
go configInformers.Start(config.Stop)

enabled, _, err := featureGateAccessor.CurrentFeatureGates()
if err != nil {
return nil, err
}
// example of future featuregate read and usage to set a variable to pass to a controller
_ = sets.NewString(enabled...).Has("AzureWorkloadIdentity")

select {
case <-featureGateAccessor.InitialFeatureGatesObserved():
enabled, disabled, _ := featureGateAccessor.CurrentFeatureGates()
klog.Infof("FeatureGates initialized: enabled=%v disabled=%v", enabled, disabled)
case <-time.After(1 * time.Minute):
klog.Errorf("timed out waiting for FeatureGate detection")
return nil, fmt.Errorf("timed out waiting for FeatureGate detection")
}

// Set up an operator manager for the operator namespace.
mgr, err := manager.New(kubeConfig, manager.Options{
Namespace: config.Namespace,
Expand Down Expand Up @@ -109,11 +167,6 @@ func New(config operatorconfig.Config, kubeConfig *rest.Config) (*Operator, erro
return nil, fmt.Errorf("failed to create ingress controller: %v", err)
}

kubeClient, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
return nil, fmt.Errorf("failed to create kube client: %w", err)
}
namespaceInformers := informers.NewSharedInformerFactoryWithOptions(kubeClient, 24*time.Hour, informers.WithNamespace(operatorcontroller.DefaultOperandNamespace))
// this only handles the case for the default router which is used for oauth-server, console, and other
// platform services. The scheduler bug will need to be fixed to correct the rest.
// Once https://bugzilla.redhat.com/show_bug.cgi?id=2062459 is fixed, this controller can be removed.
Expand All @@ -122,12 +175,7 @@ func New(config operatorconfig.Config, kubeConfig *rest.Config) (*Operator, erro
operatorcontroller.DefaultOperandNamespace,
operatorcontroller.IngressControllerDeploymentPodSelector(&operatorv1.IngressController{ObjectMeta: metav1.ObjectMeta{Name: "default"}}),
30, // minReadySeconds from deployments.apps/router-default
events.NewKubeRecorder(kubeClient.CoreV1().Events(config.Namespace), "cluster-ingress-operator", &corev1.ObjectReference{
APIVersion: "apps/v1",
Kind: "Deployment",
Namespace: config.Namespace,
Name: "ingress-operator",
}),
eventRecorder,
// ingress operator appears to be wired to a namespaced resource
v1helpers.NewFakeOperatorClient(&operatorv1.OperatorSpec{ManagementState: operatorv1.Managed}, &operatorv1.OperatorStatus{}, nil),
kubeClient,
Expand Down Expand Up @@ -193,7 +241,8 @@ func New(config operatorconfig.Config, kubeConfig *rest.Config) (*Operator, erro
config.Namespace,
operatorcontroller.DefaultOperandNamespace,
},
OperatorReleaseVersion: config.OperatorReleaseVersion,
OperatorReleaseVersion: config.OperatorReleaseVersion,
UseAzureWorkloadIdentity: useAzureWorkloadIdentity,
}); err != nil {
return nil, fmt.Errorf("failed to create dns controller: %v", err)
}
Expand Down

0 comments on commit 8c71879

Please sign in to comment.