Skip to content

Commit

Permalink
fix: fix missing status on objects
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Scott <[email protected]>
  • Loading branch information
scottd018 committed Jul 12, 2023
1 parent 3852ea1 commit 36501e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/samples/cluster/rosa_simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: rosa-simple
spec:
accountID: "660250927410"
displayName: dscott
displayName: dscott-test3
tags:
owner: dscott
iam:
Expand Down
6 changes: 3 additions & 3 deletions config/samples/machinepool/sample.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 16 additions & 2 deletions controllers/request/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 36501e7

Please sign in to comment.