Skip to content

Override enum #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $(REGISTRY_CMDS): version_flags=-ldflags "-X '$(REGISTRY_PKG)/cmd/opm/version.gi
$(REGISTRY_CMDS):
go build $(version_flags) $(GO_BUILD_OPTS) $(GO_BUILD_TAGS) -o $@ $(REGISTRY_PKG)/cmd/$(notdir $@)

$(OLM_CMDS): version_flags=-ldflags "-X $(OLM_PKG)/pkg/version.GitCommit=$(GIT_COMMIT) -X $(OLM_PKG)/pkg/version.OLMVersion=`cat staging/operator-lifecycle-manager/OLM_VERSION`"
$(OLM_CMDS): version_flags=-ldflags "-X $(OLM_PKG)/pkg/version.GitCommit=$(GIT_COMMIT) -X $(OLM_PKG)/pkg/version.OLMVersion=`cat staging/operator-lifecycle-manager/OLM_VERSION` -X $(API_PKG)/pkg/operators/v1.UnsafeFailForwardUpgradeStrategy=TechPreviewUnsafeFailForward"
$(OLM_CMDS):
go build $(version_flags) $(GO_BUILD_OPTS) $(GO_BUILD_TAGS) -o bin/$(shell basename $@) $@

Expand Down
10 changes: 9 additions & 1 deletion manifests/0000_50_olm_00-operatorgroups.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spec:
spec:
description: OperatorGroupSpec is the spec for an OperatorGroup resource.
type: object
default:
upgradeStrategy: Default
properties:
selector:
description: Selector selects the OperatorGroup's target namespaces.
Expand Down Expand Up @@ -82,8 +84,14 @@ spec:
items:
type: string
x-kubernetes-list-type: set
upgradeStrategy:
description: "UpgradeStrategy defines the upgrade strategy for operators in the namespace. There are currently two supported upgrade strategies: \n Default: OLM will only allow clusterServiceVersions to move to the replacing phase from the succeeded phase. This effectively means that OLM will not allow operators to move to the next version if an installation or upgrade has failed. \n UnsafeFailForward: OLM will allow clusterServiceVersions to move to the replacing phase from the succeeded phase or from the failed phase. Additionally, OLM will generate new installPlans when a subscription references a failed installPlan and the catalog has been updated with a new upgrade for the existing set of operators. \n WARNING: The UnsafeFailForward upgrade strategy is unsafe and may result in unexpected behavior or unrecoverable data loss unless you have deep understanding of the set of operators being managed in the namespace. OperatorGroupStatus is the status for an OperatorGroupResource."
type: string
default: Default
enum:
- Default
- TechPreviewUnsafeFailForward
status:
description: OperatorGroupStatus is the status for an OperatorGroupResource.
type: object
required:
- lastUpdated
Expand Down
5 changes: 5 additions & 0 deletions scripts/generate_crds_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ rm -rf ./manifests/* ${crddir}/*

trap "rm -rf ${tmpdir}" EXIT


# SED Commands
sed -i 's/+kubebuilder:validation:Enum=Default;UnsafeFailForward/+kubebuilder:validation:Enum=Default;TechPreviewUnsafeFailForward/g' staging/api/pkg/operators/v1/operatorgroup_types.go


${CONTROLLER_GEN} crd:crdVersions=v1 output:crd:dir=${crddir} paths=${crdsrcdir}/...
${CONTROLLER_GEN} schemapatch:manifests=${crddir} output:dir=${crddir} paths=${crdsrcdir}/...

Expand Down
10 changes: 9 additions & 1 deletion staging/api/crds/operators.coreos.com_operatorgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ spec:
spec:
description: OperatorGroupSpec is the spec for an OperatorGroup resource.
type: object
default:
upgradeStrategy: Default
properties:
selector:
description: Selector selects the OperatorGroup's target namespaces.
Expand Down Expand Up @@ -80,8 +82,14 @@ spec:
items:
type: string
x-kubernetes-list-type: set
upgradeStrategy:
description: "UpgradeStrategy defines the upgrade strategy for operators in the namespace. There are currently two supported upgrade strategies: \n Default: OLM will only allow clusterServiceVersions to move to the replacing phase from the succeeded phase. This effectively means that OLM will not allow operators to move to the next version if an installation or upgrade has failed. \n UnsafeFailForward: OLM will allow clusterServiceVersions to move to the replacing phase from the succeeded phase or from the failed phase. Additionally, OLM will generate new installPlans when a subscription references a failed installPlan and the catalog has been updated with a new upgrade for the existing set of operators. \n WARNING: The UnsafeFailForward upgrade strategy is unsafe and may result in unexpected behavior or unrecoverable data loss unless you have deep understanding of the set of operators being managed in the namespace. OperatorGroupStatus is the status for an OperatorGroupResource."
type: string
default: Default
enum:
- Default
- UnsafeFailForward
status:
description: OperatorGroupStatus is the status for an OperatorGroupResource.
type: object
required:
- lastUpdated
Expand Down
2 changes: 1 addition & 1 deletion staging/api/crds/zz_defs.go

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions staging/api/pkg/operators/v1/operatorgroup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package v1

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestUpgradeStrategy(t *testing.T) {
tests := []struct {
description string
og *OperatorGroup
expected string
}{
{
description: "NoSpec",
og: &OperatorGroup{},
expected: DefaultUpgradeStrategy,
},
{
description: "NoUpgradeStrategy",
og: &OperatorGroup{
Spec: OperatorGroupSpec{},
},
expected: DefaultUpgradeStrategy,
},
{
description: "NoUpgradeStrategyName",
og: &OperatorGroup{
Spec: OperatorGroupSpec{
UpgradeStrategy: "",
},
},
expected: DefaultUpgradeStrategy,
},
{
description: "NonSupportedUpgradeStrategyName",
og: &OperatorGroup{
Spec: OperatorGroupSpec{
UpgradeStrategy: "foo",
},
},
expected: DefaultUpgradeStrategy,
},
{
description: "UnsafeFailForwardUpgradeStrategyName",
og: &OperatorGroup{
Spec: OperatorGroupSpec{
UpgradeStrategy: "UnsafeFailForward",
},
},
expected: UnsafeFailForwardUpgradeStrategy,
},
}

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
require.EqualValues(t, tt.expected, tt.og.UpgradeStrategy())
})
}
}
42 changes: 41 additions & 1 deletion staging/api/pkg/operators/v1/operatorgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,32 @@ type OperatorGroupSpec struct {
// Static tells OLM not to update the OperatorGroup's providedAPIs annotation
// +optional
StaticProvidedAPIs bool `json:"staticProvidedAPIs,omitempty"`

// UpgradeStrategy defines the upgrade strategy for operators in the namespace.
// There are currently two supported upgrade strategies:
//
// Default: OLM will only allow clusterServiceVersions to move to the replacing
// phase from the succeeded phase. This effectively means that OLM will not
// allow operators to move to the next version if an installation or upgrade
// has failed.
//
// UnsafeFailForward: OLM will allow clusterServiceVersions to move to the
// replacing phase from the succeeded phase or from the failed phase.
// Additionally, OLM will generate new installPlans when a subscription references
// a failed installPlan and the catalog has been updated with a new upgrade for
// the existing set of operators.
//
// WARNING: The UnsafeFailForward upgrade strategy is unsafe and may result
// in unexpected behavior or unrecoverable data loss unless you have deep
// understanding of the set of operators being managed in the namespace.
// OperatorGroupStatus is the status for an OperatorGroupResource.
//
// +kubebuilder:validation:Enum=Default;TechPreviewUnsafeFailForward
// +kubebuilder:default=Default
// +optional
UpgradeStrategy string `json:"upgradeStrategy,omitempty"`
}

// OperatorGroupStatus is the status for an OperatorGroupResource.
type OperatorGroupStatus struct {
// Namespaces is the set of target namespaces for the OperatorGroup.
// +listType=set
Expand Down Expand Up @@ -76,6 +99,7 @@ type OperatorGroup struct {
metav1.ObjectMeta `json:"metadata"`

// +optional
// +kubebuilder:default={upgradeStrategy:Default}
Spec OperatorGroupSpec `json:"spec"`
Status OperatorGroupStatus `json:"status,omitempty"`
}
Expand All @@ -90,6 +114,11 @@ type OperatorGroupList struct {
Items []OperatorGroup `json:"items"`
}

const (
DefaultUpgradeStrategy = "Default"
UnsafeFailForwardUpgradeStrategy = "UnsafeFailForward"
)

// BuildTargetNamespaces returns the set of target namespaces as a sorted, comma-delimited string
func (o *OperatorGroup) BuildTargetNamespaces() string {
ns := make([]string, len(o.Status.Namespaces))
Expand All @@ -98,6 +127,17 @@ func (o *OperatorGroup) BuildTargetNamespaces() string {
return strings.Join(ns, ",")
}

// IsServiceAccountSpecified returns true if the spec has a service account name specified.
func (o *OperatorGroup) UpgradeStrategy() string {
strategyName := o.Spec.UpgradeStrategy
switch {
case strategyName == UnsafeFailForwardUpgradeStrategy:
return strategyName
default:
return DefaultUpgradeStrategy
}
}

// IsServiceAccountSpecified returns true if the spec has a service account name specified.
func (o *OperatorGroup) IsServiceAccountSpecified() bool {
if o.Spec.ServiceAccountName == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,8 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
return
}

a.logger.Infof("FailForwardStrategy == %v", operatorsv1.UnsafeFailForwardUpgradeStrategy)

if len(operatorGroup.Status.Namespaces) == 1 && operatorGroup.Status.Namespaces[0] == operatorGroup.GetNamespace() {
logger.Debug("skipping copy for OwnNamespace operatorgroup")
return
Expand Down

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

Loading