Skip to content

Commit

Permalink
Add rolling upgrade to openstack
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Sep 20, 2020
1 parent c99d85a commit 65b3899
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/kops/rollingupdatecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func RunRollingUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer
ValidateSuccessDuration: 10 * time.Second,
Ctx: ctx,
Cluster: cluster,
Clientset: clientset,
}

err = d.AdjustNeedUpdate(groups, list)
Expand Down
3 changes: 1 addition & 2 deletions pkg/instancegroups/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//pkg/featureflag:go_default_library",
"//pkg/validation:go_default_library",
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand All @@ -40,8 +41,6 @@ go_test(
embed = [":go_default_library"],
deps = [
"//cloudmock/aws/mockautoscaling:go_default_library",
"//cloudmock/openstack/mockcompute:go_default_library",
"//cloudmock/openstack/mocknetworking:go_default_library",
"//pkg/apis/kops:go_default_library",
"//pkg/assets:go_default_library",
"//pkg/client/simple/vfsclientset:go_default_library",
Expand Down
30 changes: 30 additions & 0 deletions pkg/instancegroups/instancegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"strings"
"time"

"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -371,13 +374,40 @@ func (c *RollingUpdateCluster) drainTerminateAndWait(u *cloudinstances.CloudInst
return err
}

if err := c.reconcileInstanceGroup(); err != nil {
klog.Errorf("error reconciling instance group %q: %v", u.CloudInstanceGroup.HumanName, err)
return err
}

// Wait for the minimum interval
klog.Infof("waiting for %v after terminating instance", sleepAfterTerminate)
time.Sleep(sleepAfterTerminate)

return nil
}

func (c *RollingUpdateCluster) reconcileInstanceGroup() error {
if api.CloudProviderID(c.Cluster.Spec.CloudProvider) != api.CloudProviderOpenstack {
return nil
}
rto := fi.RunTasksOptions{}
rto.InitDefaults()
applyCmd := &cloudup.ApplyClusterCmd{
Clientset: c.Clientset,
Cluster: c.Cluster,
DryRun: false,
AllowKopsDowngrade: true,
RunTasksOptions: &rto,
OutDir: "",
Phase: "",
TargetName: "direct",
LifecycleOverrides: map[string]fi.Lifecycle{},
}

return applyCmd.Run(c.Ctx)

}

func (c *RollingUpdateCluster) maybeValidate(operation string, validateCount int) error {
if c.CloudOnly {
klog.Warningf("Not validating cluster as cloudonly flag is set.")
Expand Down
4 changes: 4 additions & 0 deletions pkg/instancegroups/rollingupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sync"
"time"

"k8s.io/kops/pkg/client/simple"

"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
api "k8s.io/kops/pkg/apis/kops"
Expand Down Expand Up @@ -76,6 +78,8 @@ type RollingUpdateCluster struct {
Ctx context.Context

Cluster *api.Cluster

Clientset simple.Clientset
}

// AdjustNeedUpdate adjusts the set of instances that need updating, using factors outside those known by the cloud implementation
Expand Down
1 change: 0 additions & 1 deletion upup/pkg/fi/cloudup/openstack/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func (c *openstackCloud) DeleteInstance(i *cloudinstances.CloudInstance) error {
}

func deleteInstance(c OpenstackCloud, i *cloudinstances.CloudInstance) error {
klog.Warning("This does not work without running kops update cluster --yes in another terminal")
return deleteInstanceWithID(c, i.ID)
}

Expand Down

0 comments on commit 65b3899

Please sign in to comment.