Skip to content
Merged
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
14 changes: 10 additions & 4 deletions api/v1/clustercatalog_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ const (
AvailabilityModeUnavailable AvailabilityMode = "Unavailable"

// Condition types
TypeServing = "Serving"
ClusterCatalogTypeServing = "Serving"
ClusterCatalogTypeProgressing = "Progressing"

// Serving Reasons
ReasonAvailable = "Available"
ReasonUnavailable = "Unavailable"
ReasonUserSpecifiedUnavailable = "UserSpecifiedUnavailable"
ClusterCatalogReasonAvailable = "Available"
ClusterCatalogReasonUnavailable = "Unavailable"
ClusterCatalogReasonUserSpecifiedUnavailable = "UserSpecifiedUnavailable"

// Progressing Reasons
ClusterCatalogReasonSucceeded = "Succeeded"
ClusterCatalogReasonRetrying = "Retrying"
ClusterCatalogReasonBlocked = "Blocked"
)

// +genclient
Expand Down
39 changes: 34 additions & 5 deletions api/v1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,41 @@ type CRDUpgradeSafetyPreflightConfig struct {
}

const (
// TypeDeprecated is a rollup condition that is present when
// Condition types
ClusterExtensionTypeInstalled = "Installed"
ClusterExtensionTypeProgressing = "Progressing"
// ClusterExtensionTypeAvailable is the ClusterExtension condition that surfaces the health of the
// full set of managed objects across all active revisions. This condition may flap
// during upgrades and configuration changes.
ClusterExtensionTypeAvailable = "Available"
// ClusterExtensionTypeDeprecated is a rollup condition that is present when
// any of the deprecated conditions are present.
TypeDeprecated = "Deprecated"
TypePackageDeprecated = "PackageDeprecated"
TypeChannelDeprecated = "ChannelDeprecated"
TypeBundleDeprecated = "BundleDeprecated"
ClusterExtensionTypeDeprecated = "Deprecated"
ClusterExtensionTypePackageDeprecated = "PackageDeprecated"
ClusterExtensionTypeChannelDeprecated = "ChannelDeprecated"
ClusterExtensionTypeBundleDeprecated = "BundleDeprecated"

// Installed reasons
ClusterExtensionReasonAbsent = "Absent"

// Available reasons
ClusterExtensionReasonProbesSucceeded = "ProbesSucceeded"

// Progressing reasons
ClusterExtensionReasonRollingOut = "RollingOut"
ClusterExtensionReasonRetrying = "Retrying"
ClusterExtensionReasonBlocked = "Blocked"
ClusterExtensionReasonInvalidConfiguration = "InvalidConfiguration"

// Deprecation reasons
ClusterExtensionReasonDeprecated = "Deprecated"
ClusterExtensionReasonNotDeprecated = "NotDeprecated"
ClusterExtensionReasonDeprecationStatusUnknown = "DeprecationStatusUnknown"

// Reasons shared across condition types
ClusterExtensionReasonSucceeded = "Succeeded"
ClusterExtensionReasonFailed = "Failed"
ClusterExtensionReasonProgressDeadlineExceeded = "ProgressDeadlineExceeded"

// None will not perform CRD upgrade safety checks.
CRDUpgradeSafetyEnforcementNone CRDUpgradeSafetyEnforcement = "None"
Expand Down
16 changes: 8 additions & 8 deletions api/v1/clusterextension_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,49 @@ import (
// TODO Expand these tests to cover Types/Reasons/etc. from other APIs as well

func TestClusterExtensionTypeRegistration(t *testing.T) {
types, err := parseConstants("Type")
types, err := parseConstants("ClusterExtensionType")
if err != nil {
t.Fatalf("unable to parse Type constants %v", err)
}

for _, tt := range types {
if !slices.Contains(conditionsets.ConditionTypes, tt) {
t.Errorf("append Type%s to conditionsets.ConditionTypes in this package's init function", tt)
t.Errorf("append ClusterExtensionType%[1]s to conditionsets.ConditionTypes in this package's init function", tt)
}
}

for _, tt := range conditionsets.ConditionTypes {
if !slices.Contains(types, tt) {
t.Errorf("there must be a Type%[1]s string literal constant for type %[1]q (i.e. 'const Type%[1]s = %[1]q')", tt)
t.Errorf("there must be a ClusterExtensionType%[1]s string literal constant for type %[1]q (i.e. 'const ClusterExtensionType%[1]s = %[1]q')", tt)
}
}
}

func TestClusterExtensionReasonRegistration(t *testing.T) {
reasons, err := parseConstants("Reason")
reasons, err := parseConstants("ClusterExtensionReason")
if err != nil {
t.Fatalf("unable to parse Reason constants %v", err)
}

for _, r := range reasons {
if !slices.Contains(conditionsets.ConditionReasons, r) {
t.Errorf("append Reason%s to conditionsets.ConditionReasons in this package's init function.", r)
t.Errorf("append ClusterExtensionReason%s to conditionsets.ConditionReasons in this package's init function.", r)
}
}
for _, r := range conditionsets.ConditionReasons {
if !slices.Contains(reasons, r) {
t.Errorf("there must be a Reason%[1]s string literal constant for reason %[1]q (i.e. 'const Reason%[1]s = %[1]q')", r)
t.Errorf("there must be a ClusterExtensionReason%[1]s string literal constant for reason %[1]q (i.e. 'const ClusterExtensionReason%[1]s = %[1]q')", r)
}
}
}

// parseConstants parses the values of the top-level constants that start with the given prefix,
// in the files clusterextension_types.go and common_types.go.
// in the file clusterextension_types.go.
func parseConstants(prefix string) ([]string, error) {
fset := token.NewFileSet()
// An AST is a representation of the source code that can be traversed to extract information.
// Converting files to AST representation to extract information.
parseFiles, astFiles := []string{"clusterextension_types.go", "common_types.go"}, []*ast.File{}
parseFiles, astFiles := []string{"clusterextension_types.go"}, []*ast.File{}
for _, file := range parseFiles {
p, err := parser.ParseFile(fset, file, nil, 0)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/v1/clusterobjectdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
// Progressing condition reasons.
ClusterObjectDeploymentReasonNewClusterObjectSetProgressed = "NewClusterObjectSetProgressed"
ClusterObjectDeploymentReasonNewClusterObjectSetProgressing = "NewClusterObjectSetProgressing"
ClusterObjectDeploymentReasonProgressDeadlineExceeded = ReasonProgressDeadlineExceeded
ClusterObjectDeploymentReasonProgressDeadlineExceeded = "ProgressDeadlineExceeded"
ClusterObjectDeploymentReasonInvalidSpecification = "InvalidSpecification"
ClusterObjectDeploymentReasonRevisionPreconditionsNotMet = "RevisionPreconditionsNotMet"
ClusterObjectDeploymentReasonRevisionObjectCollision = "RevisionObjectCollision"
Expand Down
48 changes: 0 additions & 48 deletions api/v1/common_types.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ type CRDUpgradeSafetyPreflightConfig struct {
}

const (
// TypeDeprecated is a rollup condition that is present when
// ClusterExtensionTypeDeprecated is a rollup condition that is present when
// any of the deprecated conditions are present.
TypeDeprecated = "Deprecated"
TypePackageDeprecated = "PackageDeprecated"
TypeChannelDeprecated = "ChannelDeprecated"
TypeBundleDeprecated = "BundleDeprecated"
ClusterExtensionTypeDeprecated = "Deprecated"
ClusterExtensionTypePackageDeprecated = "PackageDeprecated"
ClusterExtensionTypeChannelDeprecated = "ChannelDeprecated"
ClusterExtensionTypeBundleDeprecated = "BundleDeprecated"

// None will not perform CRD upgrade safety checks.
CRDUpgradeSafetyEnforcementNone CRDUpgradeSafetyEnforcement = "None"
Expand Down
28 changes: 14 additions & 14 deletions internal/catalogd/controllers/core/clustercatalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ func nextPollResult(lastSuccessfulPoll time.Time, catalog *ocv1.ClusterCatalog)

func clearUnknownConditions(status *ocv1.ClusterCatalogStatus) {
knownTypes := sets.New[string](
ocv1.TypeServing,
ocv1.TypeProgressing,
ocv1.ClusterCatalogTypeServing,
ocv1.ClusterCatalogTypeProgressing,
)
status.Conditions = slices.DeleteFunc(status.Conditions, func(cond metav1.Condition) bool {
return !knownTypes.Has(cond.Type)
Expand All @@ -327,22 +327,22 @@ func clearUnknownConditions(status *ocv1.ClusterCatalogStatus) {

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

if err != nil {
progressingCond.Status = metav1.ConditionTrue
progressingCond.Reason = ocv1.ReasonRetrying
progressingCond.Reason = ocv1.ClusterCatalogReasonRetrying
progressingCond.Message = errorutil.SanitizeNetworkError(err)
}

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

meta.SetStatusCondition(&status.Conditions, progressingCond)
Expand All @@ -360,9 +360,9 @@ func updateStatusServing(status *ocv1.ClusterCatalogStatus, ref reference.Canoni
}
status.LastUnpacked = ptr.To(metav1.NewTime(modTime.Truncate(time.Second)))
meta.SetStatusCondition(&status.Conditions, metav1.Condition{
Type: ocv1.TypeServing,
Type: ocv1.ClusterCatalogTypeServing,
Status: metav1.ConditionTrue,
Reason: ocv1.ReasonAvailable,
Reason: ocv1.ClusterCatalogReasonAvailable,
Message: "Serving desired content from resolved source",
ObservedGeneration: generation,
})
Expand All @@ -374,9 +374,9 @@ func updateStatusProgressingUserSpecifiedUnavailable(status *ocv1.ClusterCatalog
// availability mode and are ready to progress to any future
// desired state.
progressingCond := metav1.Condition{
Type: ocv1.TypeProgressing,
Type: ocv1.ClusterCatalogTypeProgressing,
Status: metav1.ConditionTrue,
Reason: ocv1.ReasonSucceeded,
Reason: ocv1.ClusterCatalogReasonSucceeded,
Message: "Catalog availability mode is set to Unavailable",
ObservedGeneration: generation,
}
Expand All @@ -385,9 +385,9 @@ func updateStatusProgressingUserSpecifiedUnavailable(status *ocv1.ClusterCatalog
// so that users of this condition are aware that this catalog is
// intentionally not being served
servingCond := metav1.Condition{
Type: ocv1.TypeServing,
Type: ocv1.ClusterCatalogTypeServing,
Status: metav1.ConditionFalse,
Reason: ocv1.ReasonUserSpecifiedUnavailable,
Reason: ocv1.ClusterCatalogReasonUserSpecifiedUnavailable,
Message: "Catalog availability mode is set to Unavailable",
ObservedGeneration: generation,
}
Expand All @@ -401,9 +401,9 @@ func updateStatusNotServing(status *ocv1.ClusterCatalogStatus, generation int64)
status.URLs = nil
status.LastUnpacked = nil
meta.SetStatusCondition(&status.Conditions, metav1.Condition{
Type: ocv1.TypeServing,
Type: ocv1.ClusterCatalogTypeServing,
Status: metav1.ConditionFalse,
Reason: ocv1.ReasonUnavailable,
Reason: ocv1.ClusterCatalogReasonUnavailable,
ObservedGeneration: generation,
})
}
Expand Down
Loading
Loading