Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Ignore zshippable in minor version during upgrade #4378

Closed
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
3 changes: 3 additions & 0 deletions addons/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ const (
TKGDevCCPan = "devcc"

TKRAnnotationKey = "run.tanzu.vmware.com/tkr-spec"

// Zshippable postscrip added to mark a component as in development
Zshippable = "-zshippable"
)

var (
Expand Down
10 changes: 8 additions & 2 deletions addons/webhooks/clusterbootstrap_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package webhooks
import (
"context"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -484,6 +485,10 @@ func (wh *ClusterBootstrap) validateAdditionalPackagesUpdate(ctx context.Context
return allErrs
}

// ValidateClusterBootstrapPackageUpdate for unit test validateClusterBoostrapPackageUpdate only. Not intended to be called directly from outside the package.
func (wh *ClusterBootstrap) ValidateClusterBootstrapPackageUpdate(ctx context.Context, oldPkg, newPkg *runv1alpha3.ClusterBootstrapPackage, fldPath *field.Path) *field.Error {
return wh.validateClusterBootstrapPackageUpdate(ctx, oldPkg, newPkg, fldPath)
}
func (wh *ClusterBootstrap) validateClusterBootstrapPackageUpdate(ctx context.Context, oldPkg, newPkg *runv1alpha3.ClusterBootstrapPackage, fldPath *field.Path) *field.Error {
// 1. For cni, cpi, csi, kapp once created
// a. we won’t allow packageRef’s to be downgraded or change the package from something like calico to antrea
Expand Down Expand Up @@ -520,12 +525,13 @@ func (wh *ClusterBootstrap) validateClusterBootstrapPackageUpdate(ctx context.Co
}

// The package can't be downgraded
newPkgSemver, err := versions.NewRelaxedSemver(newPackageVersion)
// trim zshippable from minor if present to help on development testing
newPkgSemver, err := versions.NewRelaxedSemver(strings.TrimRight(newPackageVersion, constants.Zshippable))
if err != nil {
retErr := errors.Wrap(err, "new package version is invalid")
return field.Invalid(fldPath.Child("refName"), newPkg.RefName, retErr.Error())
}
oldPkgSemver, err := versions.NewRelaxedSemver(oldPackageVersion)
oldPkgSemver, err := versions.NewRelaxedSemver(strings.TrimRight(oldPackageVersion, constants.Zshippable))
if err != nil {
retErr := errors.Wrap(err, "old package version is invalid")
return field.Invalid(fldPath.Child("refName"), oldPkg.RefName, retErr.Error())
Expand Down
70 changes: 57 additions & 13 deletions addons/webhooks/clusterbootstrap_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/util/validation/field"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -306,6 +308,39 @@ var _ = Describe("ClusterbootstrapWebhook", func() {

})
})
Context("ValidateClusterBootstrapPackageUpdate", func() {
BeforeEach(func() {
err := createVersionedCarvelPackage(ctx, k8sClient, "oldpkg", "pkg", "0.12.1+vmware.2-tkg.2-zshippable")
if err != nil && !apierrors.IsAlreadyExists(err) {
Expect(err).NotTo(HaveOccurred())
}
err = createVersionedCarvelPackage(ctx, k8sClient, "newpkg", "pkg", "0.12.1+vmware.2-tkg.3")
if err != nil && !apierrors.IsAlreadyExists(err) {
Expect(err).NotTo(HaveOccurred())
}
})
Context(" oldPackage is 0.12.1+vmware.2-tkg.2-zshippable", func() {
Context("newPackage is 0.12.1+vmware.2-tkg.3", func() {
It("should return ok", func() {
wh := webhooks.ClusterBootstrap{Client: k8sClient}
wh.SetupWebhookWithManager(ctx, mgr)
wh.SystemNamespace = SystemNamespace
oldPackage := &runv1alpha3.ClusterBootstrapPackage{
RefName: "oldpkg",
ValuesFrom: nil,
}
newPackage := &runv1alpha3.ClusterBootstrapPackage{
RefName: "newpkg",
ValuesFrom: nil,
}
fldPath := &field.Path{}

Expect(wh.ValidateClusterBootstrapPackageUpdate(context.TODO(), oldPackage, newPackage, fldPath)).To(BeNil())
})
})

})
})
})

func assertTKRBootstrapPackageNamesContain(tkr *runv1alpha3.TanzuKubernetesRelease, name string) {
Expand Down Expand Up @@ -373,25 +408,34 @@ func createCarvelPackages(ctx context.Context, client client.Client) {
}

for _, refName := range packageRefNames {
err := client.Create(ctx, &packagev1alpha1.Package{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s.%s", refName, fakeCarvelPackageVersion),
Namespace: SystemNamespace,
},
Spec: packagev1alpha1.PackageSpec{
RefName: refName,
Version: fakeCarvelPackageVersion,
Template: packagev1alpha1.AppTemplateSpec{
Spec: &kappctrlv1alph1.AppSpec{},
},
},
})
pkgName := fmt.Sprintf("%s.%s", refName, fakeCarvelPackageVersion)
err := createVersionedCarvelPackage(ctx, client, pkgName, refName, fakeCarvelPackageVersion)
if err != nil && !apierrors.IsAlreadyExists(err) {
Expect(err).NotTo(HaveOccurred())
}
}
}

func createVersionedCarvelPackage(ctx context.Context, client client.Client, pkgName, refName, version string) error {

err := client.Create(ctx, &packagev1alpha1.Package{
ObjectMeta: metav1.ObjectMeta{
Name: pkgName,
Namespace: SystemNamespace,
},
Spec: packagev1alpha1.PackageSpec{
RefName: refName,
Version: version,
Template: packagev1alpha1.AppTemplateSpec{
Spec: &kappctrlv1alph1.AppSpec{},
},
},
})

return err

}

func deleteCarvelPackages(ctx context.Context, client client.Client) {
packageRefNames := []string{
fakeAntreaCarvelPackageRefName,
Expand Down