Skip to content

Commit

Permalink
Merge pull request #117 from cdapio/CDAP-20996-develop
Browse files Browse the repository at this point in the history
[CDAP-20996] Reduce the length of pre-upgrade and post-upgrade job names so that it does not exceed 63 char limit
  • Loading branch information
itsankit-google authored Apr 15, 2024
2 parents f032319 + 10787ad commit 5a1bcbe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21

- name: Install Kubebuilder
run: |
Expand Down
6 changes: 3 additions & 3 deletions controllers/testdata/post_upgrade_job.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"custom-resource-namespace": "default",
"using": "controllers.VersionUpdateHandler"
},
"name": "cdap-test-post-upgrade-job-1581238669880",
"name": "cdap-test-post-upgrade-job-1581238669",
"namespace": "default",
"ownerReferences": [
{
Expand All @@ -30,7 +30,7 @@
}
],
"resourceVersion": "1876398",
"selfLink": "/apis/batch/v1/namespaces/default/jobs/cdap-test-post-upgrade-job-1581233225335",
"selfLink": "/apis/batch/v1/namespaces/default/jobs/cdap-test-post-upgrade-job-1581233225",
"uid": "a0afd92d-4b0d-11ea-8611-42010a800022"
},
"spec": {
Expand All @@ -51,7 +51,7 @@
"custom-resource": "v1alpha1.CDAPMaster",
"custom-resource-name": "test",
"custom-resource-namespace": "default",
"job-name": "cdap-test-post-upgrade-job-1581233225335",
"job-name": "cdap-test-post-upgrade-job-1581233225",
"using": "controllers.VersionUpdateHandler"
}
},
Expand Down
6 changes: 3 additions & 3 deletions controllers/testdata/pre_upgrade_job.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"custom-resource-namespace": "default",
"using": "controllers.VersionUpdateHandler"
},
"name": "cdap-test-pre-upgrade-job-1581238669880",
"name": "cdap-test-pre-upgrade-job-1581238669",
"namespace": "default",
"ownerReferences": [
{
Expand All @@ -30,7 +30,7 @@
}
],
"resourceVersion": "1896807",
"selfLink": "/apis/batch/v1/namespaces/default/jobs/cdap-test-pre-upgrade-job-1581238669880",
"selfLink": "/apis/batch/v1/namespaces/default/jobs/cdap-test-pre-upgrade-job-1581238669",
"uid": "401828eb-4b1a-11ea-8611-42010a800022"
},
"spec": {
Expand All @@ -51,7 +51,7 @@
"custom-resource": "v1alpha1.CDAPMaster",
"custom-resource-name": "test",
"custom-resource-namespace": "default",
"job-name": "cdap-test-pre-upgrade-job-1581238669880",
"job-name": "cdap-test-pre-upgrade-job-1581238669",
"using": "controllers.VersionUpdateHandler"
}
},
Expand Down
31 changes: 17 additions & 14 deletions controllers/version_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,22 @@ func upgradeForBackend(master *v1alpha1.CDAPMaster, labels map[string]string, ob

// For upgrade:
// - When succeeded:
// * PreUpgradeSucceeded, PostUpgradeSucceeded and UpgradeSucceeded are set
// * Status.ImageToUse (new image) == Spec.Image (new image)
// - PreUpgradeSucceeded, PostUpgradeSucceeded and UpgradeSucceeded are set
// - Status.ImageToUse (new image) == Spec.Image (new image)
//
// - When failed, two cases
// 1) Preupgrade failed
// * PreUpgradeFailed and UpgradeFailed are set
// * Status.ImageToUse (new image) != Spec.Image (current image)
// 2) Postupgrade failed
// * PostUpgradeFailed and UpgradeFailed are set
// * Status.ImageToUse (new image) == Spec.Image (new image)
// 1. Preupgrade failed
// * PreUpgradeFailed and UpgradeFailed are set
// * Status.ImageToUse (new image) != Spec.Image (current image)
// 2. Postupgrade failed
// * PostUpgradeFailed and UpgradeFailed are set
// * Status.ImageToUse (new image) == Spec.Image (new image)
//
// For downgrade:
// - When succeeded:
// * DowngradeSucceeded is set
// * Status.ImageToUse (new image) == Spec.Image (new image)
// - DowngradeSucceeded is set
// - Status.ImageToUse (new image) == Spec.Image (new image)
//
// - When failed (currently not possible, as we just set the new version directly)
type VersionUpdateStatus struct {
// common states
Expand Down Expand Up @@ -404,8 +407,8 @@ func parseImageString(imageString string) (*Version, error) {

// compare two parsed versions
// -1: left < right
// 0: left = right
// 1: left > right
// 0: left = right
// 1: left > right
func compareVersion(l, r *Version) int {
if l.latest && r.latest {
return 0
Expand Down Expand Up @@ -501,12 +504,12 @@ func getCurrentTimeMs() int64 {

// The returned name is just the suffix of actual k8s object name, as we prepend it with const string + CR name
func getPreUpgradeJobName(startTimeMs int64) string {
return fmt.Sprintf("pre-upgrade-job-%d", startTimeMs)
return fmt.Sprintf("pre-upgrade-job-%d", startTimeMs / 1000)
}

// The returned name is just the suffix of actual k8s object name, as we prepend it with const string + CR name
func getPostUpgradeJobName(startTimeMs int64) string {
return fmt.Sprintf("post-upgrade-job-%d", startTimeMs)
return fmt.Sprintf("post-upgrade-job-%d", startTimeMs / 1000)
}

// Return pre-upgrade job spec
Expand Down

0 comments on commit 5a1bcbe

Please sign in to comment.