From b66f038512d92aaec274fd48ec6241ca20c4f011 Mon Sep 17 00:00:00 2001 From: Vu Dinh Date: Tue, 23 Jul 2019 10:24:11 -0400 Subject: [PATCH] bug(1717636): Add relatedObjects to cluster operator status Signed-off-by: Vu Dinh --- cmd/catalog/main.go | 2 +- cmd/olm/main.go | 2 +- pkg/lib/operatorstatus/status.go | 50 +++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/cmd/catalog/main.go b/cmd/catalog/main.go index 93e48a76138..7bf09e5e783 100644 --- a/cmd/catalog/main.go +++ b/cmd/catalog/main.go @@ -166,7 +166,7 @@ func main() { <-op.Ready() if *writeStatusName != "" { - operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), op.Done(), opClient, configClient) + operatorstatus.MonitorClusterStatus(*writeStatusName, *catalogNamespace, op.AtLevel(), op.Done(), opClient, configClient) } <-op.Done() diff --git a/cmd/olm/main.go b/cmd/olm/main.go index 54676edc8eb..b39176b6051 100644 --- a/cmd/olm/main.go +++ b/cmd/olm/main.go @@ -189,7 +189,7 @@ func main() { <-op.Ready() if *writeStatusName != "" { - operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), ctx.Done(), opClient, configClient) + operatorstatus.MonitorClusterStatus(*writeStatusName, *namespace, op.AtLevel(), ctx.Done(), opClient, configClient) } if *writePackageServerStatusName != "" { diff --git a/pkg/lib/operatorstatus/status.go b/pkg/lib/operatorstatus/status.go index d84c9fe22d3..342577d0f8d 100644 --- a/pkg/lib/operatorstatus/status.go +++ b/pkg/lib/operatorstatus/status.go @@ -15,11 +15,18 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/discovery" + olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1" + olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version" ) -func MonitorClusterStatus(name string, syncCh <-chan error, stopCh <-chan struct{}, opClient operatorclient.ClientInterface, configClient configv1client.ConfigV1Interface) { +const ( + clusterOperatorOLM = "operator-lifecycle-manager" + clusterOperatorCatalogSource = "operator-lifecycle-manager-catalog" +) + +func MonitorClusterStatus(name, namespace string, syncCh <-chan error, stopCh <-chan struct{}, opClient operatorclient.ClientInterface, configClient configv1client.ConfigV1Interface) { var ( syncs int successfulSyncs int @@ -100,6 +107,7 @@ func MonitorClusterStatus(name string, syncCh <-chan error, stopCh <-chan struct }, }, }) + created.Status.RelatedObjects = relatedObjects(name, namespace) if createErr != nil { log.Errorf("Failed to create cluster operator: %v\n", createErr) return @@ -220,3 +228,43 @@ func findOperatorStatusCondition(conditions []configv1.ClusterOperatorStatusCond return nil } + +// relatedObjects returns RelatedObjects in the ClusterOperator.Status. +// RelatedObjects are consumed by https://github.com/openshift/must-gather +func relatedObjects(name, namespace string) []configv1.ObjectReference { + var objectReferences []configv1.ObjectReference + switch name { + case clusterOperatorOLM: + objectReferences = []configv1.ObjectReference{ + { + Group: olmv1.GroupName, + Resource: olmv1.OperatorGroupKind, + Namespace: namespace, + }, + { + Group: olmv1alpha1.GroupName, + Resource: olmv1alpha1.ClusterServiceVersionKind, + Namespace: namespace, + }, + } + case clusterOperatorCatalogSource: + objectReferences = []configv1.ObjectReference{ + { + Group: olmv1alpha1.GroupName, + Resource: olmv1alpha1.SubscriptionKind, + Namespace: namespace, + }, + { + Group: olmv1alpha1.GroupName, + Resource: olmv1alpha1.InstallPlanKind, + Namespace: namespace, + }, + } + } + namespaces := configv1.ObjectReference{ + Resource: "namespaces", + Name: namespace, + } + objectReferences = append(objectReferences, namespaces) + return objectReferences +}