Skip to content

Commit

Permalink
feat: implementation of catalog polling feature
Browse files Browse the repository at this point in the history
  • Loading branch information
exdx committed Dec 16, 2019
1 parent 2864699 commit 6041410
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 13 deletions.
10 changes: 10 additions & 0 deletions deploy/chart/templates/0000_50_olm_06-catalogsource.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ spec:
type: string
description:
type: string
poll:
type: object
description: Poll represents the duration between successive checks of the catalog image to ensure the
latest version of the catalogsource is present.
required:
- interval
properties:
interval:
type: string
description: The real time interval between polls of the catalog image registry.
displayName:
description: Metadata
type: string
Expand Down
21 changes: 16 additions & 5 deletions pkg/api/apis/operators/catalogsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ type CatalogSourceSpec struct {
// +Optional
Image string

// Poll is used to determine the time interval between checks of the latest catalog source version.
// The catalog operator polls to see if a new version of the catalog source is available.
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
// +Optional
Poll Poll

// Secrets represent set of secrets that can be used to access the contents of the catalog.
// It is best to keep this list small, since each will need to be tried for every catalog entry.
// +Optional
Expand All @@ -59,6 +65,10 @@ type CatalogSourceSpec struct {
Icon Icon
}

type Poll struct {
Interval metav1.Duration
}

type RegistryServiceStatus struct {
Protocol string
ServiceName string
Expand All @@ -78,11 +88,12 @@ func (s *RegistryServiceStatus) Address() string {
}

type CatalogSourceStatus struct {
Message string `json:"message,omitempty"`
Reason ConditionReason `json:"reason,omitempty"`
ConfigMapResource *ConfigMapResourceReference
RegistryServiceStatus *RegistryServiceStatus
GRPCConnectionState *GRPCConnectionState
Message string `json:"message,omitempty"`
Reason ConditionReason `json:"reason,omitempty"`
ConfigMapResource *ConfigMapResourceReference
RegistryServiceStatus *RegistryServiceStatus
GRPCConnectionState *GRPCConnectionState
LatestImageRegistryPoll metav1.Time
}

type ConfigMapResourceReference struct {
Expand Down
41 changes: 41 additions & 0 deletions pkg/api/apis/operators/v1alpha1/catalogsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"fmt"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -54,6 +55,12 @@ type CatalogSourceSpec struct {
// +Optional
Image string `json:"image,omitempty"`

// Poll is used to determine the time interval between checks of the latest catalog source version.
// The catalog operator polls to see if a new version of the catalog source is available.
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
// +Optional
Poll Poll `json:"poll,omitempty"`

// Secrets represent set of secrets that can be used to access the contents of the catalog.
// It is best to keep this list small, since each will need to be tried for every catalog entry.
// +Optional
Expand All @@ -66,6 +73,10 @@ type CatalogSourceSpec struct {
Icon Icon `json:"icon,omitempty"`
}

type Poll struct {
Interval metav1.Duration `json:"interval,omitempty"`
}

type RegistryServiceStatus struct {
Protocol string `json:"protocol,omitempty"`
ServiceName string `json:"serviceName,omitempty"`
Expand All @@ -92,6 +103,9 @@ type CatalogSourceStatus struct {
// +optional
Reason ConditionReason `json:"reason,omitempty"`

// The last time the CatalogSource image registry has been polled to ensure the image is up-to-date
LatestImageRegistryPoll metav1.Time `json:"lastUpdateTime,omitempty"`

ConfigMapResource *ConfigMapResourceReference `json:"configMapReference,omitempty"`
RegistryServiceStatus *RegistryServiceStatus `json:"registryService,omitempty"`
GRPCConnectionState *GRPCConnectionState `json:"connectionState,omitempty"`
Expand Down Expand Up @@ -137,6 +151,33 @@ func (c *CatalogSource) SetError(reason ConditionReason, err error) {
}
}

func (c *CatalogSource) SetLastUpdateTime() {
c.Status.LatestImageRegistryPoll = metav1.Now()
}

// Check if it is time to update based on polling setting
func (c *CatalogSource) ReadyToUpdate() bool {
interval := c.Spec.Poll.Interval.Duration

// check poll value is not zero (default poll value)
// if polling interval is zero polling will not be done
if interval == time.Duration(0) {
return false
}

if c.Status.LatestImageRegistryPoll.IsZero() {
if c.CreationTimestamp.Add(interval).Before(time.Now()) {
return true
}
} else {
if c.Status.LatestImageRegistryPoll.Add(interval).Before(time.Now()) {
return true
}
}

return false
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// CatalogSourceList is a repository of CSVs, CRDs, and operator packages.
Expand Down
62 changes: 60 additions & 2 deletions pkg/api/apis/operators/v1alpha1/zz_generated.conversion.go

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

19 changes: 19 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.

19 changes: 19 additions & 0 deletions pkg/api/apis/operators/zz_generated.deepcopy.go

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

5 changes: 4 additions & 1 deletion pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
if healthy && in.Status.RegistryServiceStatus != nil {
logger.Debug("registry state good")
continueSync = true
return
// Check if registryService is ready for polling update
if !out.ReadyToUpdate() {
return
}
}

// Registry pod hasn't been created or hasn't been updated since the last configmap update, recreate it
Expand Down

0 comments on commit 6041410

Please sign in to comment.