Skip to content

Commit

Permalink
Merge pull request #7050 from drekle/openstack_rolling_update
Browse files Browse the repository at this point in the history
Openstack support for rolling-update status
  • Loading branch information
k8s-ci-robot authored Jun 8, 2019
2 parents 02cb57e + 2f25db8 commit 19f0da0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/client/simple/vfsclientset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ go_library(
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/secrets:go_default_library",
"//util/pkg/vfs:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/simple/vfsclientset/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -140,6 +141,10 @@ func (r *ClusterVFS) Update(c *api.Cluster, status *api.ClusterStatus) (*api.Clu
return nil, err
}

if !apiequality.Semantic.DeepEqual(old.Spec, c.Spec) {
c.SetGeneration(old.GetGeneration() + 1)
}

if err := r.writeConfig(c, r.basePath.Join(clusterName, registry.PathCluster), c, vfs.WriteOptionOnlyIfExists); err != nil {
if os.IsNotExist(err) {
return nil, err
Expand Down
13 changes: 12 additions & 1 deletion pkg/client/simple/vfsclientset/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package vfsclientset
import (
"fmt"

apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -138,7 +139,17 @@ func (c *InstanceGroupVFS) Create(g *api.InstanceGroup) (*api.InstanceGroup, err
}

func (c *InstanceGroupVFS) Update(g *api.InstanceGroup) (*api.InstanceGroup, error) {
err := c.update(c.cluster, g)

old, err := c.Get(g.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

if !apiequality.Semantic.DeepEqual(old.Spec, g.Spec) {
g.SetGeneration(old.GetGeneration() + 1)
}

err = c.update(c.cluster, g)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/openstackmodel/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
}
igMeta["k8s"] = b.ClusterName()
igMeta["KopsInstanceGroup"] = ig.Name
igMeta[openstack.INSTANCE_GROUP_GENERATION] = fmt.Sprintf("%d", ig.GetGeneration())
igMeta[openstack.CLUSTER_GENERATION] = fmt.Sprintf("%d", b.Cluster.GetGeneration())

startupScript, err := b.BootstrapScript.ResourceNodeUp(ig, b.Cluster)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/openstack/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func (c *openstackCloud) GetCloudGroups(cluster *kops.Cluster, instancegroups []
}
continue
}
groups[instancegroup.ObjectMeta.Name], err = c.osBuildCloudInstanceGroup(instancegroup, &grp, nodeMap)
groups[instancegroup.ObjectMeta.Name], err = c.osBuildCloudInstanceGroup(cluster, instancegroup, &grp, nodeMap)
if err != nil {
return nil, fmt.Errorf("error getting cloud instance group %q: %v", instancegroup.ObjectMeta.Name, err)
}
Expand Down
5 changes: 5 additions & 0 deletions upup/pkg/fi/cloudup/openstack/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (
"k8s.io/kops/util/pkg/vfs"
)

const (
INSTANCE_GROUP_GENERATION = "ig_generation"
CLUSTER_GENERATION = "cluster_generation"
)

func (c *openstackCloud) CreateInstance(opt servers.CreateOptsBuilder) (*servers.Server, error) {
var server *servers.Server

Expand Down
15 changes: 12 additions & 3 deletions upup/pkg/fi/cloudup/openstack/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package openstack

import (
"fmt"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"

"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -99,7 +100,7 @@ func matchInstanceGroup(name string, clusterName string, instancegroups []*kops.
return instancegroup, nil
}

func (c *openstackCloud) osBuildCloudInstanceGroup(ig *kops.InstanceGroup, g *servergroups.ServerGroup, nodeMap map[string]*v1.Node) (*cloudinstances.CloudInstanceGroup, error) {
func (c *openstackCloud) osBuildCloudInstanceGroup(cluster *kops.Cluster, ig *kops.InstanceGroup, g *servergroups.ServerGroup, nodeMap map[string]*v1.Node) (*cloudinstances.CloudInstanceGroup, error) {
newLaunchConfigName := g.Name
cg := &cloudinstances.CloudInstanceGroup{
HumanName: newLaunchConfigName,
Expand All @@ -114,8 +115,16 @@ func (c *openstackCloud) osBuildCloudInstanceGroup(ig *kops.InstanceGroup, g *se
klog.Warningf("ignoring instance with no instance id: %s", i)
continue
}
// TODO: how we should implement this, OS does not have launchconfigs? Should we somehow use tags in servergroups and in instances
err := cg.NewCloudInstanceGroupMember(instanceId, newLaunchConfigName, newLaunchConfigName+"-updatealways", nodeMap)
server, err := servers.Get(c.ComputeClient(), instanceId).Extract()
if err != nil {
return nil, fmt.Errorf("Failed to get instance group member: %v", err)
}
igObservedGeneration := server.Metadata[INSTANCE_GROUP_GENERATION]
clusterObservedGeneration := server.Metadata[CLUSTER_GENERATION]
observedName := fmt.Sprintf("%s-%s", clusterObservedGeneration, igObservedGeneration)
generationName := fmt.Sprintf("%d-%d", cluster.GetGeneration(), ig.Generation)

err = cg.NewCloudInstanceGroupMember(instanceId, generationName, observedName, nodeMap)
if err != nil {
return nil, fmt.Errorf("error creating cloud instance group member: %v", err)
}
Expand Down

0 comments on commit 19f0da0

Please sign in to comment.