From 7cb15b0d0ea3b371c5f3940bf2860a2a4870ceb0 Mon Sep 17 00:00:00 2001 From: Shreyas Badiger <7680410+shreyas-badiger@users.noreply.github.com> Date: Wed, 27 Jan 2021 17:12:06 -0800 Subject: [PATCH] Fix all the "make vet" errors in Controller V2 branch. (#177) * Validation step to check Nodes and ASG launch configs Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Validating launch definition after a rolling upgrade Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Resolve error log message and return statement Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Adding Functional Test (#113) * Adding BDD, workflow and badge * Changing CI workflow job name * Adding make manifests * Clarifying cron time zone comment Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * release 0.13 (#115) * release 0.13 * Update CHANGELOG.md Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * bump version (#116) Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Repo selection for CI and BDD workflows & CI step for releases (#117) * CI-BDD not on forks & Step for releases (#2) * Testing CI-BDD not on forks & Step for releases * Adding step for image with tag git-tag Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Terminate unjoined nodes Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Resolving PR comments Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Set version and update CHANGELOG for version 0.14. (#121) Co-authored-by: Shri Javadekar Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Bump version to 0.15-dev. Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Fix typo in README.md. (#125) Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Ignore the terminated instance during upgrade Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Added WARNING prefix in the logging Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Apply suggestions from code review Co-authored-by: Kevin Downey Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Capitalize sprintf to Sprintf Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Upgrade to Go 1.15 (#128) Signed-off-by: Oleg Atamanenko Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Fix few typos and simplify error returns, remove redundant types (#131) Signed-off-by: Oleg Atamanenko Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Readiness gates implementation for eager mode (#130) Signed-off-by: Oleg Atamanenko Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * Adding Functional Test (#113) * Adding BDD, workflow and badge * Changing CI workflow job name * Adding make manifests * Clarifying cron time zone comment Signed-off-by: sbadiger * Validation step to check Nodes and ASG launch configs (#112) * Validation step to check Nodes and ASG launch configs * Validating launch definition after a rolling upgrade * Resolve error log message and return statement Co-authored-by: Eytan Avisror Signed-off-by: sbadiger * release 0.13 (#115) * release 0.13 * Update CHANGELOG.md Signed-off-by: sbadiger * bump version (#116) Signed-off-by: sbadiger * Repo selection for CI and BDD workflows & CI step for releases (#117) * CI-BDD not on forks & Step for releases (#2) * Testing CI-BDD not on forks & Step for releases * Adding step for image with tag git-tag Signed-off-by: sbadiger * Terminate unjoined nodes (#120) * Validation step to check Nodes and ASG launch configs * Validating launch definition after a rolling upgrade * Resolve error log message and return statement * Terminate unjoined nodes * Resolving PR comments Co-authored-by: Eytan Avisror Signed-off-by: sbadiger * Set version and update CHANGELOG for version 0.14. (#121) Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Bump version to 0.15-dev. Signed-off-by: sbadiger * Fix bug when switching to launch templates (#136) * Update rollingupgrade_controller.go * Update rollingupgrade_controller.go Signed-off-by: Eytan Avisror * spacing fixes Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * Extract script runner to a separate type; fix work with env. variables (#132) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Set version and update CHANGELOG for version v0.15 (#137) Signed-off-by: Shri Javadekar Signed-off-by: sbadiger * Bump version to v0.16-dev. Signed-off-by: Shri Javadekar Signed-off-by: sbadiger * Propagate parent env variables to allow to talk with API Server (#144) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Bump Golang CI action to fix failed CI run (#146) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Simplify (#145) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Add Expiration to cache and do not refresh ASG if cache is not expired (#143) Signed-off-by: Oleg Atamanenko Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Fix documentation for uniform across AZ Update strategy and fix typos (#147) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Move cluster state from package level to a cluster state impl (#148) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Simplify work with intstr type. (#149) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * If instance is in standby mode already, just return (#138) Signed-off-by: Oleg Atamanenko Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Handle terminated instances gracefully. (#150) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Template version comparison fix (#155) * get template version Signed-off-by: Eytan Avisror * fix tests Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * release 0.16 (#157) Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * bump version to 0.17-dev (#158) Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * Don't uncordon node on failure to run postDrain script when IgnoreDrainFailures set (#151) * Don't uncordon node on failure to run postDrain script when IgnoreDrainFailures set Signed-off-by: Adam Malcontenti-Wilson * Test node uncordon when postDrain / postDrainWait script fails Signed-off-by: Adam Malcontenti-Wilson Signed-off-by: sbadiger * Abort on strategy failure instead of continuing (#152) * Abort on strategy failure instead of continuing Signed-off-by: Adam Malcontenti-Wilson * Remove unformatted error message placeholder Signed-off-by: Adam Malcontenti-Wilson * Explictly specify strategy for tests Signed-off-by: Adam Malcontenti-Wilson Signed-off-by: sbadiger * use NamespacedName (#160) Signed-off-by: Eytan Avisror Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Set version and update CHANGELOG for version v0.17 (#161) Signed-off-by: Shri Javadekar Signed-off-by: sbadiger * Bump version to v0.18-dev (#162) Signed-off-by: Shri Javadekar Signed-off-by: sbadiger * Move constants to types so that they can be reused (#167) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Remove separate module for pkg/log (#168) Signed-off-by: Oleg Atamanenko Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Bump dependencies. (#169) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * use standard fmt.Errorf to format error message; unify error format (#171) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Fix namespaced name order (#170) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Add instance id to the logs (#173) Signed-off-by: Oleg Atamanenko Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Bump golang and busybox (#172) Signed-off-by: Oleg Atamanenko Co-authored-by: Shri Javadekar Signed-off-by: sbadiger * Expose template list and other execution errors to logs (#166) * Log and return wrapped launchtemplate error Signed-off-by: Adam Malcontenti-Wilson * Expose execution error in logs Signed-off-by: Adam Malcontenti-Wilson Signed-off-by: sbadiger * output can contain other messages from API Server, so be more relaxed (#174) Signed-off-by: Oleg Atamanenko Signed-off-by: sbadiger * Delete README.md Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * delete all Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * scaffolding Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * add API Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * initial code Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * add more scaffolding Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * Add kubernetes API calls Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * aws API calls Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * AWS API calls & Drift detection Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * validate() function Signed-off-by: shreyas-badiger Signed-off-by: sbadiger * modified validate() Signed-off-by: sbadiger * modified validate() Signed-off-by: sbadiger * initial rotation logic Signed-off-by: Eytan Avisror Signed-off-by: sbadiger * basic script_runner without any modifications Signed-off-by: sbadiger * Fix all the vet related errors Signed-off-by: sbadiger Co-authored-by: Alfredo Garo <44888596+garomonegro@users.noreply.github.com> Co-authored-by: Eytan Avisror Co-authored-by: Shri Javadekar Co-authored-by: Shri Javadekar Co-authored-by: Shri Javadekar Co-authored-by: Craig Robson Co-authored-by: Kevin Downey Co-authored-by: Oleg Atamanenko Co-authored-by: Shreyas Badiger <7680410+hard-fault@users.noreply.github.com> Co-authored-by: Adam Malcontenti-Wilson Co-authored-by: Adam Malcontenti-Wilson Co-authored-by: Eytan Avisror --- api/v1alpha1/rollingupgrade_types.go | 8 ++++++-- controllers/providers/aws/utils.go | 19 ++++++++++--------- controllers/upgrade.go | 12 +++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/api/v1alpha1/rollingupgrade_types.go b/api/v1alpha1/rollingupgrade_types.go index 10b9110b..5804dc57 100644 --- a/api/v1alpha1/rollingupgrade_types.go +++ b/api/v1alpha1/rollingupgrade_types.go @@ -17,11 +17,12 @@ limitations under the License. package v1alpha1 import ( - "common" + "fmt" "strconv" "strings" + "github.com/keikoproj/upgrade-manager/controllers/common" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -220,13 +221,16 @@ func (r *RollingUpgrade) IsForceRefresh() bool { return r.Spec.ForceRefresh } +func (r *RollingUpgrade) StrategyMode() UpdateStrategyMode { + return r.Spec.Strategy.Mode +} func (r *RollingUpgrade) Validate() (bool, error) { strategy := r.Spec.Strategy // validating the Type value if strategy.Type == "" { r.Spec.Strategy.Type = RandomUpdateStrategy - } else if !common.ContainsEqualFold(AllowedStrategyType, strategy.Type) { + } else if !common.ContainsEqualFold(AllowedStrategyType, string(strategy.Type)) { err := fmt.Errorf("%s: Invalid value for startegy Type - %d", r.Name, strategy.MaxUnavailable.IntVal) return false, err } diff --git a/controllers/providers/aws/utils.go b/controllers/providers/aws/utils.go index e5e01bd2..f14bc819 100644 --- a/controllers/providers/aws/utils.go +++ b/controllers/providers/aws/utils.go @@ -86,15 +86,16 @@ func GetScalingAZs(instances []*autoscaling.Instance) []string { return AZs } -func SelectInstancesByAZ(instances []*autoscaling.Group) *autoscaling.Instance { - for _, instance := range group.Instances { - selectedID := aws.StringValue(instance.InstanceId) - if strings.EqualFold(instanceID, selectedID) { - return instance - } - } - return &autoscaling.Instance{} -} +// func SelectInstancesByAZ(instances []*autoscaling.Group) *autoscaling.Instance { +// for _, instance := range group.Instances { +// selectedID := aws.StringValue(instance.InstanceId) +// if strings.EqualFold(instanceID, selectedID) { +// return instance +// } +// } +// return &autoscaling.Instance{} +// } + // func ListScalingInstanceIDs(group *autoscaling.Group) []string { // instanceIDs := make([]string, 0) diff --git a/controllers/upgrade.go b/controllers/upgrade.go index 31bb193a..5dd7ac33 100644 --- a/controllers/upgrade.go +++ b/controllers/upgrade.go @@ -77,12 +77,21 @@ func (r *RollingUpgradeReconciler) ReplaceNodeBatch(rollingUpgrade *v1alpha1.Rol switch mode { case v1alpha1.UpdateStrategyModeEager: for _, target := range batch { + _ = target // Add in-progress tag // Standby // Wait for desired nodes + // predrain script + + // Issue drain/scripts concurrently - set lastDrainTime + + // post drain script + + // Wait for desired nodes + // Issue drain/scripts concurrently - set lastDrainTime // Is drained? @@ -91,6 +100,7 @@ func (r *RollingUpgradeReconciler) ReplaceNodeBatch(rollingUpgrade *v1alpha1.Rol } case v1alpha1.UpdateStrategyModeLazy: for _, target := range batch { + _ = target // Add in-progress tag // Issue drain/scripts concurrently - set lastDrainTime @@ -100,7 +110,7 @@ func (r *RollingUpgradeReconciler) ReplaceNodeBatch(rollingUpgrade *v1alpha1.Rol // Terminate - set lastTerminateTime } } - + return true, nil } func (r *RollingUpgradeReconciler) SelectTargets(rollingUpgrade *v1alpha1.RollingUpgrade, scalingGroup *autoscaling.Group) []*autoscaling.Instance {