Skip to content
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

🌱 chore: cherry pick changes from 1.5.1 to 1.5.3 #21

Merged
merged 6 commits into from
Nov 1, 2023
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
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,27 @@ jobs:
go-version: ${{ env.go_version }}
- name: generate release artifacts
run: |
export REGISTRY=docker.io/mesosphere
export PROD_REGISTRY=$REGISTRY
export STAGING_REGISTRY=$REGISTRY
export TAG=${{ env.RELEASE_TAG }}
make release
- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # tag=v1
with:
draft: true
files: out/*
body: "TODO: Copy release notes shared by the comms team"
- name: Login to Dockerhub Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
- name: Build and push docker images
run: |
export REGISTRY=docker.io/mesosphere
export PROD_REGISTRY=$REGISTRY
export STAGING_REGISTRY=$REGISTRY
export TAG=${{ env.RELEASE_TAG }}
make ALL_ARCH="amd64 arm64" docker-build-all
make ALL_ARCH="amd64 arm64" docker-push-all

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

5 changes: 4 additions & 1 deletion exp/addons/api/v1beta1/clusterresourceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type ClusterResourceSetSpec struct {
Resources []ResourceRef `json:"resources,omitempty"`

// Strategy is the strategy to be used during applying resources. Defaults to ApplyOnce. This field is immutable.
// +kubebuilder:validation:Enum=ApplyOnce;Reconcile
// +kubebuilder:validation:Enum=ApplyOnce;ApplyAlways;Reconcile
// +optional
Strategy string `json:"strategy,omitempty"`
}
Expand Down Expand Up @@ -83,6 +83,9 @@ const (
// ClusterResourceSetStrategyReconcile reapplies the resources managed by a ClusterResourceSet
// if their normalized hash changes.
ClusterResourceSetStrategyReconcile ClusterResourceSetStrategy = "Reconcile"
// ClusterResourceSetStrategyApplyAlways is the strategy where changes to the ClusterResourceSet
// are applied always if they exist already in clusters or created if they do not.
ClusterResourceSetStrategyApplyAlways ClusterResourceSetStrategy = "ApplyAlways"
)

// SetTypedStrategy sets the Strategy field to the string representation of ClusterResourceSetStrategy.
Expand Down
15 changes: 11 additions & 4 deletions exp/addons/api/v1beta1/clusterresourceset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func (m *ClusterResourceSet) Default() {
// ClusterResourceSet Strategy defaults to ApplyOnce.
if m.Spec.Strategy == "" {
m.Spec.Strategy = string(ClusterResourceSetStrategyApplyOnce)
} else if m.Spec.Strategy == string(ClusterResourceSetStrategyApplyAlways) {
m.Spec.Strategy = string(ClusterResourceSetStrategyReconcile)
}
}

Expand Down Expand Up @@ -98,10 +100,15 @@ func (m *ClusterResourceSet) validate(old *ClusterResourceSet) error {
}

if old != nil && old.Spec.Strategy != "" && old.Spec.Strategy != m.Spec.Strategy {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "strategy"), m.Spec.Strategy, "field is immutable"),
)
// Allow changing from ApplyAlways (a strategy that was added in this fork) to Reconcile.
// ApplyAlways is an "alias" for Reconcile and migrating to Reconcile will enable us to stop using a fork.
if !(old.Spec.Strategy == string(ClusterResourceSetStrategyApplyAlways) &&
m.Spec.Strategy == string(ClusterResourceSetStrategyReconcile)) {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "strategy"), m.Spec.Strategy, "field is immutable"),
)
}
}

if old != nil && !reflect.DeepEqual(old.Spec.ClusterSelector, m.Spec.ClusterSelector) {
Expand Down
29 changes: 29 additions & 0 deletions exp/addons/api/v1beta1/clusterresourceset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ func TestClusterResourcesetDefault(t *testing.T) {
g.Expect(clusterResourceSet.Spec.Strategy).To(Equal(string(ClusterResourceSetStrategyApplyOnce)))
}

func TestClusterResourcesetDefaultWithClusterResourceSetStrategyApplyAlways(t *testing.T) {
g := NewWithT(t)
clusterResourceSet := &ClusterResourceSet{
Spec: ClusterResourceSetSpec{
Strategy: string(ClusterResourceSetStrategyApplyAlways),
},
}
defaultingValidationCRS := clusterResourceSet.DeepCopy()
defaultingValidationCRS.Spec.ClusterSelector = metav1.LabelSelector{
MatchLabels: map[string]string{"foo": "bar"},
}
t.Run("for ClusterResourceSet", utildefaulting.DefaultValidateTest(defaultingValidationCRS))
clusterResourceSet.Default()

g.Expect(clusterResourceSet.Spec.Strategy).To(Equal(string(ClusterResourceSetStrategyReconcile)))
}

func TestClusterResourceSetLabelSelectorAsSelectorValidation(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -104,6 +121,18 @@ func TestClusterResourceSetStrategyImmutable(t *testing.T) {
newStrategy: "",
expectErr: true,
},
{
name: "when the Strategy has changed, but the old value was ApplyAlways",
oldStrategy: string(ClusterResourceSetStrategyApplyAlways),
newStrategy: string(ClusterResourceSetStrategyReconcile),
expectErr: false,
},
{
name: "when the Strategy has changed, but the old value was ApplyAlways and the new value is ApplyOnce",
oldStrategy: string(ClusterResourceSetStrategyApplyAlways),
newStrategy: string(ClusterResourceSetStrategyApplyOnce),
expectErr: true,
},
}

for _, tt := range tests {
Expand Down
Loading