Skip to content

Commit 586e941

Browse files
Merge pull request #960 from dinhxuanvu/relatedobjects
Bug 1717636: Add relatedObjects to cluster operator status
2 parents c59f9b4 + 6bfe15f commit 586e941

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

cmd/catalog/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func main() {
166166
<-op.Ready()
167167

168168
if *writeStatusName != "" {
169-
operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), op.Done(), opClient, configClient)
169+
operatorstatus.MonitorClusterStatus(*writeStatusName, *catalogNamespace, op.AtLevel(), op.Done(), opClient, configClient)
170170
}
171171

172172
<-op.Done()

cmd/olm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func main() {
196196
<-op.Ready()
197197

198198
if *writeStatusName != "" {
199-
operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), ctx.Done(), opClient, configClient)
199+
operatorstatus.MonitorClusterStatus(*writeStatusName, *namespace, op.AtLevel(), ctx.Done(), opClient, configClient)
200200
}
201201

202202
if *writePackageServerStatusName != "" {

pkg/lib/operatorstatus/status.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ import (
1515
"k8s.io/apimachinery/pkg/util/wait"
1616
"k8s.io/client-go/discovery"
1717

18+
olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
19+
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
1820
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1921
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
2022
)
2123

22-
func MonitorClusterStatus(name string, syncCh <-chan error, stopCh <-chan struct{}, opClient operatorclient.ClientInterface, configClient configv1client.ConfigV1Interface) {
24+
const (
25+
clusterOperatorOLM = "operator-lifecycle-manager"
26+
clusterOperatorCatalogSource = "operator-lifecycle-manager-catalog"
27+
)
28+
29+
func MonitorClusterStatus(name, namespace string, syncCh <-chan error, stopCh <-chan struct{}, opClient operatorclient.ClientInterface, configClient configv1client.ConfigV1Interface) {
2330
var (
2431
syncs int
2532
successfulSyncs int
@@ -105,6 +112,7 @@ func MonitorClusterStatus(name string, syncCh <-chan error, stopCh <-chan struct
105112
},
106113
},
107114
})
115+
created.Status.RelatedObjects = relatedObjects(name, namespace)
108116
if createErr != nil {
109117
log.Errorf("Failed to create cluster operator: %v\n", createErr)
110118
return
@@ -234,3 +242,43 @@ func findOperatorStatusCondition(conditions []configv1.ClusterOperatorStatusCond
234242

235243
return nil
236244
}
245+
246+
// relatedObjects returns RelatedObjects in the ClusterOperator.Status.
247+
// RelatedObjects are consumed by https://github.com/openshift/must-gather
248+
func relatedObjects(name, namespace string) []configv1.ObjectReference {
249+
var objectReferences []configv1.ObjectReference
250+
switch name {
251+
case clusterOperatorOLM:
252+
objectReferences = []configv1.ObjectReference{
253+
{
254+
Group: olmv1.GroupName,
255+
Resource: olmv1.OperatorGroupKind,
256+
Namespace: namespace,
257+
},
258+
{
259+
Group: olmv1alpha1.GroupName,
260+
Resource: olmv1alpha1.ClusterServiceVersionKind,
261+
Namespace: namespace,
262+
},
263+
}
264+
case clusterOperatorCatalogSource:
265+
objectReferences = []configv1.ObjectReference{
266+
{
267+
Group: olmv1alpha1.GroupName,
268+
Resource: olmv1alpha1.SubscriptionKind,
269+
Namespace: namespace,
270+
},
271+
{
272+
Group: olmv1alpha1.GroupName,
273+
Resource: olmv1alpha1.InstallPlanKind,
274+
Namespace: namespace,
275+
},
276+
}
277+
}
278+
namespaces := configv1.ObjectReference{
279+
Resource: "namespaces",
280+
Name: namespace,
281+
}
282+
objectReferences = append(objectReferences, namespaces)
283+
return objectReferences
284+
}

0 commit comments

Comments
 (0)