Skip to content

Refactor upgrade logic to skip pre upgrade job in case of patch upgrades #137

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

anshumanks
Copy link
Contributor

@anshumanks anshumanks commented Feb 11, 2025

Refactor upgrade logic to skip pre upgrade job in case of patch upgrades

Description

This change prevents pre upgrade job from stopping pipelines in case of patch upgrades.

Code change

  • Modified upgrade-job.yaml, spec.go, version_update.go, constants.go

Unit Tests

  • Modified version_update_test.go, pre_upgrade_job.json
  • Modified old tests to incorporate new return value from compareVersions function (-2 for patch upgrade)
  • Added a new test to check for patch upgrade
  • Modified json file to incorporate new argument added to pre upgrade job

@@ -45,7 +45,7 @@ spec:
{{end}}
{{if .PreUpgrade}}
- name: pre-upgrade
args: ["io.cdap.cdap.master.upgrade.UpgradeJobMain", "{{.HostName}}", "11015"]
args: ["io.cdap.cdap.master.upgrade.UpgradeJobMain", "{{.HostName}}", "11015", "{{.SkipPreUpgrade}}"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the argument being set if the preupgrade job doesn't need to be started?

@@ -418,9 +422,24 @@ func compareVersion(l, r *Version) int {
return -1
}

lenL, lenR := len(l.components), len(r.components)
// Check if it only a patch upgrade
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting is broken. Please run make vet fmt to fix it.

func (s *VersionUpgradeJobSpec) SetSkipPreUpgrade(isPatchUpgrade bool) *VersionUpgradeJobSpec {
s.SkipPreUpgrade = isPatchUpgrade && s.SkipPreUpgradeFlag
return s
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing new line at the end of the file.

@@ -607,3 +611,8 @@ func (s *VersionUpgradeJobSpec) SetPostUpgrade(isPostUpgrade bool) *VersionUpgra
s.PostUpgrade = isPostUpgrade
return s
}

func (s *VersionUpgradeJobSpec) SetSkipPreUpgrade(isPatchUpgrade bool) *VersionUpgradeJobSpec {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the term patch upgrade

@@ -68,6 +68,7 @@ const (
confTwillSecurityWorkerSecretDiskPath = "twill.security.worker.secret.disk.path"
confJMXServerPort = "jmx.metrics.collector.server.port"
confSecretMountDefaultMode = "secret.mount.default.mode"
confSkipPreUpgradeFlag = "cdap-operator.skip.preupgrade-job"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be named cdap-operator.preupgrade-job.skip for consistency.

@@ -577,6 +577,8 @@ type VersionUpgradeJobSpec struct {
HConf string `json:"hadoopConf,omitempty"`
PreUpgrade bool `json:"preUpgrade,omitempty"`
PostUpgrade bool `json:"postUpgrade,omitempty"`
SkipPreUpgradeFlag bool `json:"skipPreUpgradeFlag,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a need for 2 fields for the same things?

@@ -55,6 +55,21 @@ var _ = Describe("Controller Suite", func() {
Expect(compareVersion(high, low)).To(Equal(1))
}
})
It("Compare image versions in patch upgrade", func() {
imagePairs := []Pair{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is formatting broken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants