Skip to content

Commit cfff3fc

Browse files
committedNov 18, 2024
fix all errors after openshift's library-go and api bumps
1 parent 314e628 commit cfff3fc

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed
 

‎Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ RUN go build -ldflags "-X $GO_PACKAGE/pkg/version.versionFromGit=$(git describe
77
FROM registry.svc.ci.openshift.org/openshift/origin-v4.6:base
88
COPY --from=builder /go/src/github.com/openshift/cluster-csi-snapshot-controller-operator/csi-snapshot-controller-operator /usr/bin/
99
COPY manifests /manifests
10-
COPY vendor/github.com/openshift/api/operator/v1/0000_80_csi_snapshot_controller_operator_01_crd.yaml manifests/01_config.crd.yaml
10+
COPY vendor/github.com/openshift/api/operator/v1/zz_generated.crd-manifests/0000_80_csi-snapshot-controller_01_csisnapshotcontrollers.crd.yaml manifests/01_config.crd.yaml
1111
ENTRYPOINT ["/usr/bin/csi-snapshot-controller-operator"]
1212
LABEL io.openshift.release.operator=true

‎Dockerfile.ocp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ RUN go build -ldflags "-X $GO_PACKAGE/pkg/version.versionFromGit=$(git describe
77
FROM registry.ci.openshift.org/ocp/4.18:base-rhel9
88
COPY --from=builder /go/src/github.com/openshift/cluster-csi-snapshot-controller-operator/csi-snapshot-controller-operator /usr/bin/
99
COPY manifests /manifests
10-
COPY vendor/github.com/openshift/api/operator/v1/0000_80_csi_snapshot_controller_operator_01_crd.yaml manifests/01_config.crd.yaml
10+
COPY vendor/github.com/openshift/api/operator/v1/zz_generated.crd-manifests/0000_80_csi-snapshot-controller_01_csisnapshotcontrollers.crd.yaml manifests/01_config.crd.yaml
1111
ENTRYPOINT ["/usr/bin/csi-snapshot-controller-operator"]
1212
LABEL io.openshift.release.operator=true

‎pkg/dependencymagnet/dependencymagnet.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
package dependencymagnet
77

88
import (
9+
_ "github.com/openshift/api/operator/v1/zz_generated.crd-manifests"
910
_ "github.com/openshift/build-machinery-go"
1011
)

‎pkg/operator/starter.go

+45-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
operatorv1 "github.com/openshift/api/operator/v1"
1414
configclient "github.com/openshift/client-go/config/clientset/versioned"
1515
configinformer "github.com/openshift/client-go/config/informers/externalversions"
16+
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
1617
"github.com/openshift/cluster-csi-snapshot-controller-operator/assets"
1718
"github.com/openshift/library-go/pkg/config/client"
1819
"github.com/openshift/library-go/pkg/controller/controllercmd"
@@ -38,6 +39,7 @@ import (
3839
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3940
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
4041
"k8s.io/apimachinery/pkg/labels"
42+
"k8s.io/apimachinery/pkg/runtime"
4143
"k8s.io/apimachinery/pkg/runtime/schema"
4244
"k8s.io/client-go/dynamic"
4345
"k8s.io/client-go/dynamic/dynamicinformer"
@@ -46,6 +48,7 @@ import (
4648
"k8s.io/client-go/rest"
4749
"k8s.io/client-go/tools/cache"
4850
"k8s.io/klog/v2"
51+
"k8s.io/utils/clock"
4952
"k8s.io/utils/ptr"
5053
)
5154

@@ -124,7 +127,16 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
124127
// Create GenericOperatorClient. This is used by the library-go controllers created down below
125128
// Operator CR is in the guest cluster.
126129
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+
)
128140
if err != nil {
129141
return err
130142
}
@@ -160,7 +172,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
160172

161173
// Verify whether the VolumeGroupSnapshot feature is enabled or not. This variable will be
162174
// used to decided what resources will be deployed in the cluster.
163-
volumeGroupSnapshotAPIEnabled := featureGates.Enabled(configv1.FeatureGateVolumeGroupSnapshot)
175+
volumeGroupSnapshotAPIEnabled := featureGates.Enabled(configv1.FeatureGateName("VolumeGroupSnapshot"))
164176

165177
namespacedAssetFunc := namespaceReplacer(assets.ReadFile, "${CONTROLPLANE_NAMESPACE}", controlPlaneNamespace)
166178
guestStaticResourceController := staticresourcecontroller.NewStaticResourceController(
@@ -281,7 +293,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
281293
deploymentHooks = []dc.DeploymentHookFunc{
282294
csidrivercontrollerservicecontroller.WithControlPlaneTopologyHook(guestConfigInformers),
283295
csidrivercontrollerservicecontroller.WithReplicasHook(
284-
guestKubeInformersForNamespaces.InformersFor("").Core().V1().Nodes().Lister(),
296+
guestConfigInformers,
285297
),
286298
withVolumeGroupSnapshotWebhook(volumeGroupSnapshotAPIEnabled),
287299
}
@@ -745,3 +757,33 @@ func withVolumeGroupSnapshotWebhook(enabled bool) dc.DeploymentHookFunc {
745757
return nil
746758
}
747759
}
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

Comments
 (0)
Please sign in to comment.