-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
758af46
commit 357da51
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package defaultaddons | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/kris-nova/logger" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/weaveworks/eksctl/pkg/printers" | ||
|
||
apierrs "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
const ( | ||
// KubeProxy is the name of the kube-proxy addon | ||
KubeProxy = "kube-proxy" | ||
) | ||
|
||
// UpdateKubeProxyImageTag updates image tag for kube-system:damoneset/kube-proxy based to match controlPlaneVersion | ||
func UpdateKubeProxyImageTag(clientSet kubernetes.Interface, controlPlaneVersion string, dryRun bool) error { | ||
printer := printers.NewJSONPrinter() | ||
|
||
d, err := clientSet.Apps().DaemonSets(metav1.NamespaceSystem).Get(KubeProxy, metav1.GetOptions{}) | ||
if err != nil { | ||
if apierrs.IsNotFound(err) { | ||
logger.Warning("%q was not found", KubeProxy) | ||
return nil | ||
} | ||
return errors.Wrapf(err, "getting %s", KubeProxy) | ||
} | ||
if numContainers := len(d.Spec.Template.Spec.Containers); !(numContainers >= 1) { | ||
return fmt.Errorf("%s has %d containers, expected at least 1", KubeProxy, numContainers) | ||
} | ||
|
||
if err := printer.LogObj(logger.Debug, KubeProxy+" [current] = \\\n%s\n", d); err != nil { | ||
return err | ||
} | ||
|
||
image := &d.Spec.Template.Spec.Containers[0].Image | ||
imageParts := strings.Split(*image, ":") | ||
|
||
if len(imageParts) != 2 { | ||
return fmt.Errorf("unexpected image format %q for %q", *image, KubeProxy) | ||
} | ||
|
||
desiredTag := "v" + controlPlaneVersion | ||
|
||
if imageParts[1] == desiredTag { | ||
logger.Debug("imageParts = %v, desiredTag = %s", imageParts, desiredTag) | ||
logger.Info("%q is already up-to-date", KubeProxy) | ||
return nil | ||
} | ||
|
||
if dryRun { | ||
logger.Critical("%q is not up-to-date", KubeProxy) | ||
return nil | ||
} | ||
|
||
imageParts[1] = desiredTag | ||
*image = strings.Join(imageParts, ":") | ||
|
||
if err := printer.LogObj(logger.Debug, KubeProxy+" [updated] = \\\n%s\n", d); err != nil { | ||
return err | ||
} | ||
if _, err := clientSet.Apps().DaemonSets(metav1.NamespaceSystem).Update(d); err != nil { | ||
return err | ||
} | ||
|
||
logger.Info("%q is now up-to-date", KubeProxy) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/kris-nova/logger" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
|
||
defaultaddons "github.com/weaveworks/eksctl/pkg/addons/default" | ||
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha4" | ||
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils" | ||
"github.com/weaveworks/eksctl/pkg/eks" | ||
) | ||
|
||
func updateKubeProxyCmd(g *cmdutils.Grouping) *cobra.Command { | ||
p := &api.ProviderConfig{} | ||
cfg := api.NewClusterConfig() | ||
|
||
cmd := &cobra.Command{ | ||
Use: "update-kube-proxy", | ||
Short: "Update kube-proxy add-on to ensure image matches Kubernetes control plane version", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := doUpdateKubeProxy(p, cfg, cmdutils.GetNameArg(args), cmd); err != nil { | ||
logger.Critical("%s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
group := g.New(cmd) | ||
|
||
group.InFlagSet("General", func(fs *pflag.FlagSet) { | ||
fs.StringVarP(&cfg.Metadata.Name, "name", "n", "", "EKS cluster name (required)") | ||
cmdutils.AddRegionFlag(fs, p) | ||
cmdutils.AddConfigFileFlag(&clusterConfigFile, fs) | ||
}) | ||
|
||
cmdutils.AddCommonFlagsForAWS(group, p, false) | ||
|
||
group.AddTo(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func doUpdateKubeProxy(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg string, cmd *cobra.Command) error { | ||
if err := api.Register(); err != nil { | ||
return err | ||
} | ||
|
||
if err := cmdutils.LoadMetadata(p, cfg, clusterConfigFile, nameArg, cmd); err != nil { | ||
return err | ||
} | ||
|
||
ctl := eks.New(p, cfg) | ||
meta := cfg.Metadata | ||
|
||
if !ctl.IsSupportedRegion() { | ||
return cmdutils.ErrUnsupportedRegion(p) | ||
} | ||
logger.Info("using region %s", meta.Region) | ||
|
||
if err := ctl.CheckAuth(); err != nil { | ||
return err | ||
} | ||
|
||
if err := ctl.GetCredentials(cfg); err != nil { | ||
return errors.Wrapf(err, "getting credentials for cluster %q", meta.Name) | ||
} | ||
|
||
clientSet, err := ctl.NewStdClientSet(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cprv, err := ctl.ControlPlaneReleaseVersion(clientSet) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return defaultaddons.UpdateKubeProxyImageTag(clientSet, cprv, false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters