Skip to content

Commit

Permalink
Add a check to see if workload cluster client is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Sedef committed Mar 6, 2020
1 parent 4b9ceb0 commit c25a579
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
3 changes: 0 additions & 3 deletions cmd/clusterctl/test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
<<<<<<< HEAD
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
=======
>>>>>>> update kube-proxy daemonset tag
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,17 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, cluster *
return r.upgradeControlPlane(ctx, cluster, kcp, ownedMachines, requireUpgrade)
}

//If we've made it this far, we can assume that all control-plane machines are up to date
workloadCluster, err := r.managementCluster.GetWorkloadCluster(ctx, util.ObjectKey(cluster))
//If we've made it this far, we can assume that all owned machines are up to date
w, err := r.managementCluster.GetWorkloadCluster(ctx, util.ObjectKey(cluster))
if err != nil {
logger.Error(err, "failed to get remote client for workload cluster")
} else {
err = workloadCluster.UpdateKubeProxyImage(ctx, kcp)
if err != nil {
logger.Error(err, "failed updating kube-proxy image")
return ctrl.Result{}, err
if w.IsWorkloadClusterUp(ctx) {
err = w.UpdateKubeProxyImage(ctx, kcp)
if err != nil {
logger.Error(err, "failed updating kube-proxy image")
return ctrl.Result{}, err
}
}
}
numMachines := len(ownedMachines)
Expand Down
23 changes: 14 additions & 9 deletions controlplane/kubeadm/internal/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type etcdClientFor interface {

// WorkloadCluster defines all behaviors necessary to upgrade kubernetes on a workload cluster
type WorkloadCluster interface {
IsWorkloadClusterUp(ctx context.Context) bool

// Basic health and status behaviors

ClusterStatus(ctx context.Context) (ClusterStatus, error)
Expand All @@ -81,6 +83,13 @@ type Workload struct {
etcdClientGenerator etcdClientFor
}

func (w *Workload) IsWorkloadClusterUp(ctx context.Context) bool {
if w == nil {
return false
}
return true
}

func (w *Workload) getControlPlaneNodes(ctx context.Context) (*corev1.NodeList, error) {
nodes := &corev1.NodeList{}
labels := map[string]string{
Expand Down Expand Up @@ -569,17 +578,13 @@ func modifyImageTag(image, tagName string) (string, error) {

}

// if tagging is successful, return the full image name (registry/repo:tag)
if _, ok := namedRef.(reference.Tagged); ok {
return reference.FamiliarString(reference.TagNameOnly(namedTagged)), nil
}

return "", errors.New("failed to update image tag")
return reference.FamiliarString(reference.TagNameOnly(namedTagged)), nil
}

func (c *Workload) UpdateKubeProxyImage(ctx context.Context, kcp *controlplanev1.KubeadmControlPlane) error {
func (w *Workload) UpdateKubeProxyImage(ctx context.Context, kcp *controlplanev1.KubeadmControlPlane) error {
ds := &appsv1.DaemonSet{}
if err := c.Client.Get(ctx, ctrlclient.ObjectKey{Name: kubeProxyDaemonSetName, Namespace: metav1.NamespaceSystem}, ds); err != nil && !apierrors.IsNotFound(err) {
err := w.Client.Get(ctx, ctrlclient.ObjectKey{Name: kubeProxyDaemonSetName, Namespace: metav1.NamespaceSystem}, ds)
if err != nil && !apierrors.IsNotFound(err) {
return errors.Wrapf(err, "failed to determine if %s daemonset already exists", kubeProxyDaemonSetName)
} else if err != nil {
// if kube-proxy is missing, return without errors
Expand All @@ -593,7 +598,7 @@ func (c *Workload) UpdateKubeProxyImage(ctx context.Context, kcp *controlplanev1

if len(ds.Spec.Template.Spec.Containers) > 0 && ds.Spec.Template.Spec.Containers[0].Image != newImageName {
ds.Spec.Template.Spec.Containers[0].Image = newImageName
if err := c.Client.Update(ctx, ds); err != nil {
if err := w.Client.Update(ctx, ds); err != nil {
return errors.Wrap(err, "error updating kube-proxy DaemonSet")
}
}
Expand Down

0 comments on commit c25a579

Please sign in to comment.