Skip to content

Commit

Permalink
bump ClusterCatalog API to v1
Browse files Browse the repository at this point in the history
Signed-off-by: Per Goncalves da Silva <[email protected]>
  • Loading branch information
Per Goncalves da Silva committed Nov 7, 2024
1 parent 20acf03 commit 5a47124
Show file tree
Hide file tree
Showing 27 changed files with 438 additions and 438 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Procedure steps marked with an asterisk (`*`) are likely to change with future A

```sh
$ kubectl apply -f - << EOF
apiVersion: olm.operatorframework.io/v1alpha1
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: operatorhubio
Expand All @@ -42,7 +42,7 @@ Procedure steps marked with an asterisk (`*`) are likely to change with future A
Namespace:
Labels: olm.operatorframework.io/metadata.name=operatorhubio
Annotations: <none>
API Version: olm.operatorframework.io/v1alpha1
API Version: olm.operatorframework.io/v1
Kind: ClusterCatalog
Metadata:
Creation Timestamp: 2024-10-17T13:48:46Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alpha1
package v1

import (
"context"
Expand All @@ -23,7 +23,7 @@ import (
func TestImageSourceCELValidationRules(t *testing.T) {
validators := fieldValidatorsFromFile(t, "../../../config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml")
pth := "openAPIV3Schema.properties.spec.properties.source.properties.image"
validator, found := validators["v1alpha1"][pth]
validator, found := validators["v1"][pth]
require.True(t, found)

for name, tc := range map[string]struct {
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestImageSourceCELValidationRules(t *testing.T) {
func TestResolvedImageSourceCELValidation(t *testing.T) {
validators := fieldValidatorsFromFile(t, "../../../config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml")
pth := "openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref"
validator, found := validators["v1alpha1"][pth]
validator, found := validators["v1"][pth]
require.True(t, found)

for name, tc := range map[string]struct {
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestResolvedImageSourceCELValidation(t *testing.T) {
func TestClusterCatalogURLsCELValidation(t *testing.T) {
validators := fieldValidatorsFromFile(t, "../../../config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml")
pth := "openAPIV3Schema.properties.status.properties.urls.properties.base"
validator, found := validators["v1alpha1"][pth]
validator, found := validators["v1"][pth]
require.True(t, found)
for name, tc := range map[string]struct {
urls ClusterCatalogURLs
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestClusterCatalogURLsCELValidation(t *testing.T) {
func TestSourceCELValidation(t *testing.T) {
validators := fieldValidatorsFromFile(t, "../../../config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml")
pth := "openAPIV3Schema.properties.spec.properties.source"
validator, found := validators["v1alpha1"][pth]
validator, found := validators[GroupVersion.Version][pth]
require.True(t, found)
for name, tc := range map[string]struct {
source CatalogSource
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestSourceCELValidation(t *testing.T) {
func TestResolvedSourceCELValidation(t *testing.T) {
validators := fieldValidatorsFromFile(t, "../../../config/base/crd/bases/olm.operatorframework.io_clustercatalogs.yaml")
pth := "openAPIV3Schema.properties.status.properties.resolvedSource"
validator, found := validators["v1alpha1"][pth]
validator, found := validators[GroupVersion.Version][pth]

require.True(t, found)
for name, tc := range map[string]struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the core v1alpha1 API group
// Package v1 contains API Schema definitions for the core v1 API group
// +kubebuilder:object:generate=true
// +groupName=olm.operatorframework.io
package v1alpha1
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "olm.operatorframework.io", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "olm.operatorframework.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down

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

4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
crwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/operator-framework/catalogd/api/core/v1alpha1"
catalogdv1 "github.com/operator-framework/catalogd/api/core/v1"
corecontrollers "github.com/operator-framework/catalogd/internal/controllers/core"
"github.com/operator-framework/catalogd/internal/features"
"github.com/operator-framework/catalogd/internal/garbagecollection"
Expand All @@ -76,7 +76,7 @@ const (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(catalogdv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
name: v1
schema:
openAPIV3Schema:
description: |-
Expand Down
2 changes: 1 addition & 1 deletion config/base/default/clustercatalogs/default-catalogs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: olm.operatorframework.io/v1alpha1
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: operatorhubio
Expand Down
4 changes: 2 additions & 2 deletions config/base/manager/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-olm-operatorframework-io-v1alpha1-clustercatalog
path: /mutate-olm-operatorframework-io-v1-clustercatalog
failurePolicy: Fail
name: inject-metadata-name.olm.operatorframework.io
rules:
- apiGroups:
- olm.operatorframework.io
apiVersions:
- v1alpha1
- v1
operations:
- CREATE
- UPDATE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: olm.operatorframework.io/v1alpha1
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: operatorhubio
Expand Down
2 changes: 1 addition & 1 deletion docs/fetching-catalog-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ This section outlines a way of exposing the `Catalogd` Service's endpoints outsi

```sh
$ kubectl apply -f - << EOF
apiVersion: olm.operatorframework.io/v1alpha1
apiVersion: olm.operatorframework.io/v1
kind: ClusterCatalog
metadata:
name: operatorhubio
Expand Down
66 changes: 33 additions & 33 deletions internal/controllers/core/clustercatalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/operator-framework/catalogd/api/core/v1alpha1"
catalogdv1 "github.com/operator-framework/catalogd/api/core/v1"
"github.com/operator-framework/catalogd/internal/source"
"github.com/operator-framework/catalogd/internal/storage"
)
Expand Down Expand Up @@ -86,7 +86,7 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
l.Info("reconcile starting")
defer l.Info("reconcile ending")

existingCatsrc := v1alpha1.ClusterCatalog{}
existingCatsrc := catalogdv1.ClusterCatalog{}
if err := r.Client.Get(ctx, req.NamespacedName, &existingCatsrc); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (r *ClusterCatalogReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.ClusterCatalog{}).
For(&catalogdv1.ClusterCatalog{}).
Complete(r)
}

Expand All @@ -157,11 +157,11 @@ func (r *ClusterCatalogReconciler) SetupWithManager(mgr ctrl.Manager) error {
// to add the ctrl.Result type back as a return value. Adding a comment to ignore
// linting from the linter that was fussing about this.
// nolint:unparam
func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *v1alpha1.ClusterCatalog) (ctrl.Result, error) {
func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *catalogdv1.ClusterCatalog) (ctrl.Result, error) {
l := log.FromContext(ctx)
// Check if the catalog availability is set to disabled, if true then
// unset base URL, delete it from the cache and set appropriate status
if catalog.Spec.AvailabilityMode == v1alpha1.AvailabilityModeUnavailable {
if catalog.Spec.AvailabilityMode == catalogdv1.AvailabilityModeUnavailable {
// Delete the catalog from local cache
err := r.deleteCatalogCache(ctx, catalog)
if err != nil {
Expand Down Expand Up @@ -262,7 +262,7 @@ func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *v1alp
return nextPollResult(unpackResult.LastSuccessfulPollAttempt.Time, catalog), nil
}

func (r *ClusterCatalogReconciler) getCurrentState(catalog *v1alpha1.ClusterCatalog) (*v1alpha1.ClusterCatalogStatus, storedCatalogData, bool) {
func (r *ClusterCatalogReconciler) getCurrentState(catalog *catalogdv1.ClusterCatalog) (*catalogdv1.ClusterCatalogStatus, storedCatalogData, bool) {
r.storedCatalogsMu.RLock()
storedCatalog, hasStoredCatalog := r.storedCatalogs[catalog.Name]
r.storedCatalogsMu.RUnlock()
Expand All @@ -279,10 +279,10 @@ func (r *ClusterCatalogReconciler) getCurrentState(catalog *v1alpha1.ClusterCata
return expectedStatus, storedCatalog, hasStoredCatalog
}

func nextPollResult(lastSuccessfulPoll time.Time, catalog *v1alpha1.ClusterCatalog) ctrl.Result {
func nextPollResult(lastSuccessfulPoll time.Time, catalog *catalogdv1.ClusterCatalog) ctrl.Result {
var requeueAfter time.Duration
switch catalog.Spec.Source.Type {
case v1alpha1.SourceTypeImage:
case catalogdv1.SourceTypeImage:
if catalog.Spec.Source.Image != nil && catalog.Spec.Source.Image.PollIntervalMinutes != nil {
pollDuration := time.Duration(*catalog.Spec.Source.Image.PollIntervalMinutes) * time.Minute
jitteredDuration := wait.Jitter(pollDuration, requeueJitterMaxFactor)
Expand All @@ -292,64 +292,64 @@ func nextPollResult(lastSuccessfulPoll time.Time, catalog *v1alpha1.ClusterCatal
return ctrl.Result{RequeueAfter: requeueAfter}
}

func clearUnknownConditions(status *v1alpha1.ClusterCatalogStatus) {
func clearUnknownConditions(status *catalogdv1.ClusterCatalogStatus) {
knownTypes := sets.New[string](
v1alpha1.TypeServing,
v1alpha1.TypeProgressing,
catalogdv1.TypeServing,
catalogdv1.TypeProgressing,
)
status.Conditions = slices.DeleteFunc(status.Conditions, func(cond metav1.Condition) bool {
return !knownTypes.Has(cond.Type)
})
}

func updateStatusProgressing(status *v1alpha1.ClusterCatalogStatus, generation int64, err error) {
func updateStatusProgressing(status *catalogdv1.ClusterCatalogStatus, generation int64, err error) {
progressingCond := metav1.Condition{
Type: v1alpha1.TypeProgressing,
Type: catalogdv1.TypeProgressing,
Status: metav1.ConditionTrue,
Reason: v1alpha1.ReasonSucceeded,
Reason: catalogdv1.ReasonSucceeded,
Message: "Successfully unpacked and stored content from resolved source",
ObservedGeneration: generation,
}

if err != nil {
progressingCond.Status = metav1.ConditionTrue
progressingCond.Reason = v1alpha1.ReasonRetrying
progressingCond.Reason = catalogdv1.ReasonRetrying
progressingCond.Message = err.Error()
}

if errors.Is(err, reconcile.TerminalError(nil)) {
progressingCond.Status = metav1.ConditionFalse
progressingCond.Reason = v1alpha1.ReasonBlocked
progressingCond.Reason = catalogdv1.ReasonBlocked
}

meta.SetStatusCondition(&status.Conditions, progressingCond)
}

func updateStatusServing(status *v1alpha1.ClusterCatalogStatus, result source.Result, baseURL string, generation int64) {
func updateStatusServing(status *catalogdv1.ClusterCatalogStatus, result source.Result, baseURL string, generation int64) {
status.ResolvedSource = result.ResolvedSource
if status.URLs == nil {
status.URLs = &v1alpha1.ClusterCatalogURLs{}
status.URLs = &catalogdv1.ClusterCatalogURLs{}
}
status.URLs.Base = baseURL
status.LastUnpacked = ptr.To(metav1.NewTime(result.UnpackTime))
meta.SetStatusCondition(&status.Conditions, metav1.Condition{
Type: v1alpha1.TypeServing,
Type: catalogdv1.TypeServing,
Status: metav1.ConditionTrue,
Reason: v1alpha1.ReasonAvailable,
Reason: catalogdv1.ReasonAvailable,
Message: "Serving desired content from resolved source",
ObservedGeneration: generation,
})
}

func updateStatusProgressingUserSpecifiedUnavailable(status *v1alpha1.ClusterCatalogStatus, generation int64) {
func updateStatusProgressingUserSpecifiedUnavailable(status *catalogdv1.ClusterCatalogStatus, generation int64) {
// Set Progressing condition to True with reason Succeeded
// since we have successfully progressed to the unavailable
// availability mode and are ready to progress to any future
// desired state.
progressingCond := metav1.Condition{
Type: v1alpha1.TypeProgressing,
Type: catalogdv1.TypeProgressing,
Status: metav1.ConditionTrue,
Reason: v1alpha1.ReasonSucceeded,
Reason: catalogdv1.ReasonSucceeded,
Message: "Catalog availability mode is set to Unavailable",
ObservedGeneration: generation,
}
Expand All @@ -358,9 +358,9 @@ func updateStatusProgressingUserSpecifiedUnavailable(status *v1alpha1.ClusterCat
// so that users of this condition are aware that this catalog is
// intentionally not being served
servingCond := metav1.Condition{
Type: v1alpha1.TypeServing,
Type: catalogdv1.TypeServing,
Status: metav1.ConditionFalse,
Reason: v1alpha1.ReasonUserSpecifiedUnavailable,
Reason: catalogdv1.ReasonUserSpecifiedUnavailable,
Message: "Catalog availability mode is set to Unavailable",
ObservedGeneration: generation,
}
Expand All @@ -369,19 +369,19 @@ func updateStatusProgressingUserSpecifiedUnavailable(status *v1alpha1.ClusterCat
meta.SetStatusCondition(&status.Conditions, servingCond)
}

func updateStatusNotServing(status *v1alpha1.ClusterCatalogStatus, generation int64) {
func updateStatusNotServing(status *catalogdv1.ClusterCatalogStatus, generation int64) {
status.ResolvedSource = nil
status.URLs = nil
status.LastUnpacked = nil
meta.SetStatusCondition(&status.Conditions, metav1.Condition{
Type: v1alpha1.TypeServing,
Type: catalogdv1.TypeServing,
Status: metav1.ConditionFalse,
Reason: v1alpha1.ReasonUnavailable,
Reason: catalogdv1.ReasonUnavailable,
ObservedGeneration: generation,
})
}

func (r *ClusterCatalogReconciler) needsPoll(lastSuccessfulPoll time.Time, catalog *v1alpha1.ClusterCatalog) bool {
func (r *ClusterCatalogReconciler) needsPoll(lastSuccessfulPoll time.Time, catalog *catalogdv1.ClusterCatalog) bool {
// If polling is disabled, we don't need to poll.
if catalog.Spec.Source.Image.PollIntervalMinutes == nil {
return false
Expand All @@ -393,8 +393,8 @@ func (r *ClusterCatalogReconciler) needsPoll(lastSuccessfulPoll time.Time, catal
}

// Compare resources - ignoring status & metadata.finalizers
func checkForUnexpectedFieldChange(a, b v1alpha1.ClusterCatalog) bool {
a.Status, b.Status = v1alpha1.ClusterCatalogStatus{}, v1alpha1.ClusterCatalogStatus{}
func checkForUnexpectedFieldChange(a, b catalogdv1.ClusterCatalog) bool {
a.Status, b.Status = catalogdv1.ClusterCatalogStatus{}, catalogdv1.ClusterCatalogStatus{}
a.Finalizers, b.Finalizers = []string{}, []string{}
return !equality.Semantic.DeepEqual(a, b)
}
Expand All @@ -408,7 +408,7 @@ func (f finalizerFunc) Finalize(ctx context.Context, obj client.Object) (crfinal
func (r *ClusterCatalogReconciler) setupFinalizers() error {
f := crfinalizer.NewFinalizers()
err := f.Register(fbcDeletionFinalizer, finalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {
catalog, ok := obj.(*v1alpha1.ClusterCatalog)
catalog, ok := obj.(*catalogdv1.ClusterCatalog)
if !ok {
panic("could not convert object to clusterCatalog")
}
Expand All @@ -428,7 +428,7 @@ func (r *ClusterCatalogReconciler) deleteStoredCatalog(catalogName string) {
delete(r.storedCatalogs, catalogName)
}

func (r *ClusterCatalogReconciler) deleteCatalogCache(ctx context.Context, catalog *v1alpha1.ClusterCatalog) error {
func (r *ClusterCatalogReconciler) deleteCatalogCache(ctx context.Context, catalog *catalogdv1.ClusterCatalog) error {
if err := r.Storage.Delete(catalog.Name); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
return err
Expand Down
Loading

0 comments on commit 5a47124

Please sign in to comment.