From 36501e78e9efd8f21998c34cd4f542174e8b3450 Mon Sep 17 00:00:00 2001 From: Dustin Scott Date: Wed, 12 Jul 2023 16:33:44 -0500 Subject: [PATCH] fix: fix missing status on objects Signed-off-by: Dustin Scott --- config/samples/cluster/rosa_simple.yaml | 2 +- config/samples/machinepool/sample.yaml | 6 +++--- controllers/request/cluster.go | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/config/samples/cluster/rosa_simple.yaml b/config/samples/cluster/rosa_simple.yaml index 0139781..67fa63b 100644 --- a/config/samples/cluster/rosa_simple.yaml +++ b/config/samples/cluster/rosa_simple.yaml @@ -4,7 +4,7 @@ metadata: name: rosa-simple spec: accountID: "660250927410" - displayName: dscott + displayName: dscott-test3 tags: owner: dscott iam: diff --git a/config/samples/machinepool/sample.yaml b/config/samples/machinepool/sample.yaml index a4b0e98..f59749c 100644 --- a/config/samples/machinepool/sample.yaml +++ b/config/samples/machinepool/sample.yaml @@ -1,15 +1,15 @@ apiVersion: ocm.mobb.redhat.com/v1alpha1 kind: MachinePool metadata: - name: sample + name: sample-missing spec: wait: false - clusterName: "my-cluster" + clusterName: "dscott-test3" minimumNodesPerZone: 1 maximumNodesPerZone: 1 instanceType: m5.xlarge labels: - owner: my-user + owner: dscott aws: spotInstances: enabled: false diff --git a/controllers/request/cluster.go b/controllers/request/cluster.go index 346b8e0..e593ca8 100644 --- a/controllers/request/cluster.go +++ b/controllers/request/cluster.go @@ -6,6 +6,8 @@ import ( "reflect" clustersmgmtv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" "github.com/rh-mobb/ocm-operator/pkg/kubernetes" ) @@ -49,8 +51,10 @@ func GetUpstreamCluster(request Cluster, client ClusterFetcher) (cluster *cluste return cluster, fmt.Errorf("%s: [%s] - %w", errRetrieveClusterMessage, request.GetClusterName(), ErrMissingClusterID) } } else { + var response *clustersmgmtv1.ClusterGetResponse + // retrieve the cluster from ocm by id - response, err := client.For(request.GetObject().GetClusterID()).Get().Send() + response, err = client.For(request.GetObject().GetClusterID()).Get().Send() if err != nil { if response.Status() == http.StatusNotFound { return cluster, nil @@ -61,7 +65,17 @@ func GetUpstreamCluster(request Cluster, client ClusterFetcher) (cluster *cluste } // keep track of the original object - original := request.GetObject() + object := request.GetObject().DeepCopyObject() + + // convert the client object to a runtime object. to do this, + // we convert to an unstructured object which satisfies both a client.Object + // and runtime.Object interface. + // TODO: this is a little sloppy and needs some attention. + objectMap, objectErr := runtime.DefaultUnstructuredConverter.ToUnstructured(object) + if objectErr != nil { + return cluster, fmt.Errorf("unable to convert client.Object to runtime.Object - %w", err) + } + original := &unstructured.Unstructured{Object: objectMap} // update the object request.SetClusterStatus(cluster)