@@ -13,6 +13,7 @@ import (
13
13
operatorv1 "github.com/openshift/api/operator/v1"
14
14
configclient "github.com/openshift/client-go/config/clientset/versioned"
15
15
configinformer "github.com/openshift/client-go/config/informers/externalversions"
16
+ applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
16
17
"github.com/openshift/cluster-csi-snapshot-controller-operator/assets"
17
18
"github.com/openshift/library-go/pkg/config/client"
18
19
"github.com/openshift/library-go/pkg/controller/controllercmd"
@@ -38,6 +39,7 @@ import (
38
39
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
39
40
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
40
41
"k8s.io/apimachinery/pkg/labels"
42
+ "k8s.io/apimachinery/pkg/runtime"
41
43
"k8s.io/apimachinery/pkg/runtime/schema"
42
44
"k8s.io/client-go/dynamic"
43
45
"k8s.io/client-go/dynamic/dynamicinformer"
@@ -46,6 +48,7 @@ import (
46
48
"k8s.io/client-go/rest"
47
49
"k8s.io/client-go/tools/cache"
48
50
"k8s.io/klog/v2"
51
+ "k8s.io/utils/clock"
49
52
"k8s.io/utils/ptr"
50
53
)
51
54
@@ -124,7 +127,16 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
124
127
// Create GenericOperatorClient. This is used by the library-go controllers created down below
125
128
// Operator CR is in the guest cluster.
126
129
gvr := operatorv1 .SchemeGroupVersion .WithResource ("csisnapshotcontrollers" )
127
- guestOperatorClient , dynamicInformers , err := goc .NewClusterScopedOperatorClientWithConfigName (guestKubeConfig , gvr , "cluster" )
130
+ gvk := operatorv1 .SchemeGroupVersion .WithKind ("CSISnapshotController" )
131
+ guestOperatorClient , dynamicInformers , err := goc .NewClusterScopedOperatorClientWithConfigName (
132
+ clock.RealClock {},
133
+ guestKubeConfig ,
134
+ gvr ,
135
+ gvk ,
136
+ "cluster" ,
137
+ extractOperatorSpec ,
138
+ extractOperatorStatus ,
139
+ )
128
140
if err != nil {
129
141
return err
130
142
}
@@ -160,7 +172,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
160
172
161
173
// Verify whether the VolumeGroupSnapshot feature is enabled or not. This variable will be
162
174
// used to decided what resources will be deployed in the cluster.
163
- volumeGroupSnapshotAPIEnabled := featureGates .Enabled (configv1 .FeatureGateVolumeGroupSnapshot )
175
+ volumeGroupSnapshotAPIEnabled := featureGates .Enabled (configv1 .FeatureGateName ( "VolumeGroupSnapshot" ) )
164
176
165
177
namespacedAssetFunc := namespaceReplacer (assets .ReadFile , "${CONTROLPLANE_NAMESPACE}" , controlPlaneNamespace )
166
178
guestStaticResourceController := staticresourcecontroller .NewStaticResourceController (
@@ -281,7 +293,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
281
293
deploymentHooks = []dc.DeploymentHookFunc {
282
294
csidrivercontrollerservicecontroller .WithControlPlaneTopologyHook (guestConfigInformers ),
283
295
csidrivercontrollerservicecontroller .WithReplicasHook (
284
- guestKubeInformersForNamespaces . InformersFor ( "" ). Core (). V1 (). Nodes (). Lister () ,
296
+ guestConfigInformers ,
285
297
),
286
298
withVolumeGroupSnapshotWebhook (volumeGroupSnapshotAPIEnabled ),
287
299
}
@@ -745,3 +757,33 @@ func withVolumeGroupSnapshotWebhook(enabled bool) dc.DeploymentHookFunc {
745
757
return nil
746
758
}
747
759
}
760
+
761
+ func extractOperatorSpec (obj * unstructured.Unstructured , fieldManager string ) (* applyoperatorv1.OperatorSpecApplyConfiguration , error ) {
762
+ castObj := & operatorv1.CSISnapshotController {}
763
+ if err := runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , castObj ); err != nil {
764
+ return nil , fmt .Errorf ("unable to convert to CSISnapshotController: %w" , err )
765
+ }
766
+ ret , err := applyoperatorv1 .ExtractCSISnapshotController (castObj , fieldManager )
767
+ if err != nil {
768
+ return nil , fmt .Errorf ("unable to extract fields for %q: %w" , fieldManager , err )
769
+ }
770
+ if ret .Spec == nil {
771
+ return nil , nil
772
+ }
773
+ return & ret .Spec .OperatorSpecApplyConfiguration , nil
774
+ }
775
+ func extractOperatorStatus (obj * unstructured.Unstructured , fieldManager string ) (* applyoperatorv1.OperatorStatusApplyConfiguration , error ) {
776
+ castObj := & operatorv1.CSISnapshotController {}
777
+ if err := runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , castObj ); err != nil {
778
+ return nil , fmt .Errorf ("unable to convert to CSISnapshotController: %w" , err )
779
+ }
780
+ ret , err := applyoperatorv1 .ExtractCSISnapshotControllerStatus (castObj , fieldManager )
781
+ if err != nil {
782
+ return nil , fmt .Errorf ("unable to extract fields for %q: %w" , fieldManager , err )
783
+ }
784
+
785
+ if ret .Status == nil {
786
+ return nil , nil
787
+ }
788
+ return & ret .Status .OperatorStatusApplyConfiguration , nil
789
+ }
0 commit comments