Skip to content

Commit

Permalink
bug(1717636): Add relatedObjects to cluster operator status
Browse files Browse the repository at this point in the history
Signed-off-by: Vu Dinh <[email protected]>
  • Loading branch information
dinhxuanvu committed Jul 31, 2019
1 parent 037ead3 commit ac5dd0a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
13 changes: 13 additions & 0 deletions pkg/lib/operatorstatus/clusteroperatorwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import (

configv1 "github.com/openshift/api/config/v1"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
pkmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
)

const (
clusterOperatorPackageServer = "operator-lifecycle-manager-packageserver"
)

// NewWriter returns a new instance of Writer.
func NewWriter(discovery discovery.DiscoveryInterface, client configv1client.ConfigV1Interface) *Writer {
return &Writer{
Expand Down Expand Up @@ -44,6 +49,14 @@ func (w *Writer) EnsureExists(name string) (existing *configv1.ClusterOperator,
Name: name,
},
}
if name == clusterOperatorPackageServer {
co.Status.RelatedObjects = []configv1.ObjectReference{
{
Group: pkmv1.Group,
Resource: pkmv1.PackageManifestKind,
},
}
}
existing, err = w.client.ClusterOperators().Create(co)
return
}
Expand Down
50 changes: 49 additions & 1 deletion pkg/lib/operatorstatus/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit ac5dd0a

Please sign in to comment.