Skip to content

Commit 6bfe15f

Browse files
committed
bug(1717636): Add relatedObjects to cluster operator status
Signed-off-by: Vu Dinh <[email protected]>
1 parent 26e2cc3 commit 6bfe15f

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
@@ -100,6 +107,7 @@ func MonitorClusterStatus(name string, syncCh <-chan error, stopCh <-chan struct
100107
},
101108
},
102109
})
110+
created.Status.RelatedObjects = relatedObjects(name, namespace)
103111
if createErr != nil {
104112
log.Errorf("Failed to create cluster operator: %v\n", createErr)
105113
return
@@ -220,3 +228,43 @@ func findOperatorStatusCondition(conditions []configv1.ClusterOperatorStatusCond
220228

221229
return nil
222230
}
231+
232+
// relatedObjects returns RelatedObjects in the ClusterOperator.Status.
233+
// RelatedObjects are consumed by https://github.com/openshift/must-gather
234+
func relatedObjects(name, namespace string) []configv1.ObjectReference {
235+
var objectReferences []configv1.ObjectReference
236+
switch name {
237+
case clusterOperatorOLM:
238+
objectReferences = []configv1.ObjectReference{
239+
{
240+
Group: olmv1.GroupName,
241+
Resource: olmv1.OperatorGroupKind,
242+
Namespace: namespace,
243+
},
244+
{
245+
Group: olmv1alpha1.GroupName,
246+
Resource: olmv1alpha1.ClusterServiceVersionKind,
247+
Namespace: namespace,
248+
},
249+
}
250+
case clusterOperatorCatalogSource:
251+
objectReferences = []configv1.ObjectReference{
252+
{
253+
Group: olmv1alpha1.GroupName,
254+
Resource: olmv1alpha1.SubscriptionKind,
255+
Namespace: namespace,
256+
},
257+
{
258+
Group: olmv1alpha1.GroupName,
259+
Resource: olmv1alpha1.InstallPlanKind,
260+
Namespace: namespace,
261+
},
262+
}
263+
}
264+
namespaces := configv1.ObjectReference{
265+
Resource: "namespaces",
266+
Name: namespace,
267+
}
268+
objectReferences = append(objectReferences, namespaces)
269+
return objectReferences
270+
}

0 commit comments

Comments
 (0)