Repository: gruntwork-io/kubergrunt
Pull request #97 (2020-10-13 19:13:13)

Bump VPC CNI version
The docs in https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html now point to `v1.7.5`.


Patch:
diff --git a/eks/sync.go b/eks/sync.go
index 730fd48..7a92323 100644
--- a/eks/sync.go
+++ b/eks/sync.go
@@ -12,6 +12,7 @@ import (
 	"strings"
 
 	"github.com/aws/aws-sdk-go/aws"
+	"github.com/blang/semver/v4"
 	"github.com/gruntwork-io/gruntwork-cli/collections"
 	"github.com/gruntwork-io/gruntwork-cli/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,10 +44,10 @@ var (
 	}
 
 	amazonVPCCNIVersionLookupTable = map[string]string{
-		"1.17": "1.6",
-		"1.16": "1.6",
-		"1.15": "1.6",
-		"1.14": "1.6",
+		"1.17": "1.7.5",
+		"1.16": "1.7.5",
+		"1.15": "1.7.5",
+		"1.14": "1.7.5",
 	}
 )
 
@@ -282,6 +283,20 @@ func updateCoreDNSDeploymentImage(clientset *kubernetes.Clientset, targetImage s
 	return nil
 }
 
+// getBaseURLForVPCCNIManifest returns the base github URL where the manifest for the VPC CNI is located given the
+// requested version.
+func getBaseURLForVPCCNIManifest(vpcCNIVersion string) (string, error) {
+	// Extract the major and minor version of the VPC CNI version as it is needed to construct the URL for the
+	// deployment config.
+	parsedVPCCNIVersion, err := semver.Make(vpcCNIVersion)
+	if err != nil {
+		return "", err
+	}
+	majorMinorVPCCNIVersion := fmt.Sprintf("%d.%d", parsedVPCCNIVersion.Major, parsedVPCCNIVersion.Minor)
+	baseURL := fmt.Sprintf("https://raw.githubusercontent.com/aws/amazon-vpc-cni-k8s/v%s/config/v%s/", vpcCNIVersion, majorMinorVPCCNIVersion)
+	return baseURL, nil
+}
+
 // updateVPCCNI will apply the manifest to deploy the latest patch release of the target AWS VPC CNI version. Ideally we
 // would implement this using the raw Kubernetes API, but the CNI manifest contains additional resources on top of the
 // daemonset, and thus it is better to apply the manifests directly using kubectl than to translate it into underlying
@@ -291,7 +306,10 @@ func updateVPCCNI(kubectlOptions *kubectl.KubectlOptions, region string, vpcCNIV
 
 	// Figure out the manifest URL based on region
 	// Reference: https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html
-	baseURL := fmt.Sprintf("https://raw.githubusercontent.com/aws/amazon-vpc-cni-k8s/release-%s/config/v%s/", vpcCNIVersion, vpcCNIVersion)
+	baseURL, err := getBaseURLForVPCCNIManifest(vpcCNIVersion)
+	if err != nil {
+		return err
+	}
 	if strings.HasPrefix(region, "cn-") {
 		manifestPath = baseURL + "aws-k8s-cni-cn.yaml"
 	} else if region == "us-gov-east-1" {
diff --git a/go.mod b/go.mod
index 92f4c99..fd670e3 100644
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.14
 
 require (
 	github.com/aws/aws-sdk-go v1.34.27
+	github.com/blang/semver/v4 v4.0.0
 	github.com/gruntwork-io/gruntwork-cli v0.7.0
 	github.com/gruntwork-io/terratest v0.30.0
 	github.com/mitchellh/go-homedir v1.1.0
diff --git a/go.sum b/go.sum
index 7391505..cf12e8e 100644
--- a/go.sum
+++ b/go.sum
@@ -68,7 +68,10 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
 github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
 github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
+github.com/blang/semver v3.5.0+incompatible h1:CGxCgetQ64DKk7rdZ++Vfnb1+ogGNnB17OJKJXD2Cfs=
 github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
+github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
+github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
 github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
 github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=


Test patch:
diff --git a/eks/sync_test.go b/eks/sync_test.go
index db5a17f..d504fb5 100644
--- a/eks/sync_test.go
+++ b/eks/sync_test.go
@@ -10,6 +10,14 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
+func TestGetBaseURLForVPCCNIManifest(t *testing.T) {
+	t.Parallel()
+	expected := "https://raw.githubusercontent.com/aws/amazon-vpc-cni-k8s/v1.7.5/config/v1.7/"
+	actual, err := getBaseURLForVPCCNIManifest("1.7.5")
+	require.NoError(t, err)
+	assert.Equal(t, expected, actual)
+}
+
 func TestDownloadVPCCNIManifestAndUpdateRegion(t *testing.T) {
 	t.Parallel()