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

Ezml 1226 versions semantic control #600

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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/bluek8s/kubedirector
go 1.16

require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 // indirect
github.com/go-logr/logr v0.1.0
github.com/google/gofuzz v1.1.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ github.com/coreos/etcd v3.3.15+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down
20 changes: 16 additions & 4 deletions pkg/validator/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/bluek8s/kubedirector/pkg/observer"
"github.com/bluek8s/kubedirector/pkg/secretkeys"
"github.com/bluek8s/kubedirector/pkg/shared"
semver "github.com/coreos/go-semver/semver"
av1beta1 "k8s.io/api/admission/v1beta1"
v1 "k8s.io/api/authentication/v1"
core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -379,11 +380,22 @@ func validateGeneralClusterChanges(
}

// App version should be different from previous one
if prevCrApp.Spec.Version == crApp.Spec.Version {
prevVer, err := semver.NewVersion(prevCrApp.Spec.Version)
if err != nil {
valErrors = append(valErrors, fmt.Sprintf(invalidVersionFmt, prevCrApp.Spec.Version))
return valErrors
}
newVer, err := semver.NewVersion(crApp.Spec.Version)
if err != nil {
valErrors = append(valErrors, fmt.Sprintf(invalidVersionFmt, crApp.Spec.Version))
return valErrors
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, prevVer and/or newVer can be nil if the version string is not understood by semver. In those cases we should also reject the upgrade.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, my mistake. In those cases, New will panic, which is bad for us.

Try using NewVersion (instead of New) as in https://github.com/coreos/go-semver/blob/main/example.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

if !prevVer.LessThan(*newVer) {
appModifiedMsg := fmt.Sprintf(
versionIsNotModified,
crApp.Spec.DistroID,
crApp.Spec.Version,
versionIsNotNewer,
prevVer.String(),
newVer.String(),
)
valErrors = append(valErrors, appModifiedMsg)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/validator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const (

clusterNotReady = "The %s cluster spec cannot be changed, as currently it is busy with other changes."
clusterAppIsUpgrading = "The %s cluster already is upgrading, but it can be rolled back to the previous app"
versionIsNotModified = "The application %s of version %s is already running at the current cluster. Change the version for upgrade."
versionIsNotNewer = "The candidate app version %s is not newer than version %s that is already running at the current cluster."
invalidVersionFmt = "The version string %s cannot be recognized according Semantic Versioning rules (see https://semver.org/)."
appNotUpgradable = "The application %s of version %s doesn't support live upgrade. "

invalidDistroID = "Invalid application with distroId: %s. Expected application with distroId: %s"
Expand Down