Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/api/apis/operators/v1alpha1/catalogsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ func (c *CatalogSource) Address() string {
if c.Spec.Address != "" {
return c.Spec.Address
}
return c.Status.RegistryServiceStatus.Address()
if c.Status.RegistryServiceStatus != nil {
return c.Status.RegistryServiceStatus.Address()
}
return ""
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
61 changes: 51 additions & 10 deletions pkg/api/apis/operators/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type SubscriptionStatus struct {
// +optional
InstallPlanRef *corev1.ObjectReference `json:"installPlanRef,omitempty"`

// CatalogStatus contains the Subscription's view of its relevant CatalogSources' status.
// It is used to determine SubscriptionStatusConditions related to CatalogSources.
// +optional
CatalogStatus []SubscriptionCatalogStatus `json:"catalogStatus,omitempty"`

// LastUpdated represents the last time that the Subscription status was updated.
LastUpdated metav1.Time `json:"lastUpdated"`
}
Expand All @@ -74,6 +79,52 @@ type InstallPlanReference struct {
UID types.UID `json:"uuid"`
}

// NewInstallPlanReference returns an InstallPlanReference for the given ObjectReference.
func NewInstallPlanReference(ref *corev1.ObjectReference) *InstallPlanReference {
return &InstallPlanReference{
APIVersion: ref.APIVersion,
Kind: ref.Kind,
Name: ref.Name,
UID: ref.UID,
}
}

// SubscriptionCatalogStatus describes a Subscription's view of a CatalogSource's status.
type SubscriptionCatalogStatus struct {
// CatalogSourceRef is a reference to a CatalogSource.
CatalogSourceRef *corev1.ObjectReference `json:"catalogSourceRef"`

// LastUpdated represents the last time that the CatalogSourceHealth changed
LastUpdated metav1.Time `json:"lastUpdated"`

// Healthy is true if the CatalogSource is healthy; false otherwise.
Healthy bool `json:"healthy"`
}

// SetSubscriptionCatalogStatus sets the SubscriptionStatus' CatalogStatus field as the given slice if it differs
// from the stored value. Returns true if a change was made, false otherwise.
func (status *SubscriptionStatus) SetSubscriptionCatalogStatus(catalogStatus []SubscriptionCatalogStatus) bool {
if len(status.CatalogStatus) != len(catalogStatus) {
status.CatalogStatus = catalogStatus
return true
}

// TODO: dedupe catalogStatus?

set := map[SubscriptionCatalogStatus]struct{}{}
for _, cs := range status.CatalogStatus {
set[cs] = struct{}{}
}
for _, cs := range catalogStatus {
if _, ok := set[cs]; !ok {
status.CatalogStatus = catalogStatus
return true
}
}

return false
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
type Subscription struct {
Expand All @@ -99,13 +150,3 @@ func (s *Subscription) GetInstallPlanApproval() Approval {
}
return ApprovalAutomatic
}

// NewInstallPlanReference returns an InstallPlanReference for the given ObjectReference.
func NewInstallPlanReference(ref *corev1.ObjectReference) *InstallPlanReference {
return &InstallPlanReference{
APIVersion: ref.APIVersion,
Kind: ref.Kind,
Name: ref.Name,
UID: ref.UID,
}
}
29 changes: 29 additions & 0 deletions pkg/api/apis/operators/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions pkg/controller/operators/catalog/metaview.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package catalog

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

opcache "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/cache"
)

// metaViewer is a transparent viewer that can be used as a basis for more complex viewers.
// It holds a set of commonly used utilities.
// TODO: we probably don't want to embed Operator.
type metaViewer struct {
*Operator
now func() metav1.Time
namespace string
}

var _ opcache.Viewer = &metaViewer{}

func (viewer *metaViewer) Key(obj interface{}) (key string, err error) {
// Use the most common key func (namespace/name)
// TODO: could we use metaViewer to store anything that implements meta.Interface by default?
return cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
}

func (viewer *metaViewer) KeyByView(view interface{}) (key string, err error) {
// Use the most common key func (namespace/name)
// TODO: could we use metaViewer to store anything that implements meta.Interface by default?
return cache.DeletionHandlingMetaNamespaceKeyFunc(view)
}

func (viewer *metaViewer) View(obj interface{}) (view interface{}, err error) {
// Passthrough
view = obj
return
}

type metaViewerOption func(*metaViewer)

func withNamespace(namespace string) metaViewerOption {
return func(viewer *metaViewer) {
viewer.namespace = namespace
}
}

// newMetaViewer returns a new metaViewer.
func newMetaViewer(op *Operator, options ...metaViewerOption) *metaViewer {
viewer := &metaViewer{
Operator: op,
now: timeNow,
namespace: op.namespace,
}

for _, option := range options {
option(viewer)
}

return viewer
}
Loading