From e4fafa6065c7d185ed724f70148bf37f94813cbc Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 21 Feb 2018 17:31:57 -0500 Subject: [PATCH] Use legacy image registry gcr.io/google_containers for <= 1.9 The k8s.gcr.io prefix is an alias, but for CI builds we run from a docker load, and we only double-tag from 1.10 onwards. For versions prior to 1.10, remap k8s.gcr.io to the old name. This also means that we won't start using the aliased names on existing clusters, which could otherwise be surprising to users. --- hack/.packages | 1 + pkg/assets/BUILD.bazel | 2 ++ pkg/assets/builder.go | 29 +++++++++++++++++-- .../cloudformation.json.extracted.yaml | 20 ++++++------- .../cloudformation.json.extracted.yaml | 20 ++++++------- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/hack/.packages b/hack/.packages index 13af8f817f..c80374060d 100644 --- a/hack/.packages +++ b/hack/.packages @@ -81,6 +81,7 @@ k8s.io/kops/pkg/formatter k8s.io/kops/pkg/instancegroups k8s.io/kops/pkg/jsonutils k8s.io/kops/pkg/k8scodecs +k8s.io/kops/pkg/k8sversion k8s.io/kops/pkg/kopscodecs k8s.io/kops/pkg/kubeconfig k8s.io/kops/pkg/kubemanifest diff --git a/pkg/assets/BUILD.bazel b/pkg/assets/BUILD.bazel index 923043e99d..94b05e365a 100644 --- a/pkg/assets/BUILD.bazel +++ b/pkg/assets/BUILD.bazel @@ -7,11 +7,13 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/apis/kops:go_default_library", + "//pkg/apis/kops/util:go_default_library", "//pkg/featureflag:go_default_library", "//pkg/kubemanifest:go_default_library", "//pkg/values:go_default_library", "//util/pkg/hashing:go_default_library", "//util/pkg/vfs:go_default_library", + "//vendor/github.com/blang/semver:go_default_library", "//vendor/github.com/golang/glog:go_default_library", ], ) diff --git a/pkg/assets/builder.go b/pkg/assets/builder.go index 0ab278a1c0..dfbdfa6f1a 100644 --- a/pkg/assets/builder.go +++ b/pkg/assets/builder.go @@ -24,9 +24,11 @@ import ( "path" "strings" + "github.com/blang/semver" "github.com/golang/glog" "k8s.io/kops/pkg/apis/kops" + "k8s.io/kops/pkg/apis/kops/util" "k8s.io/kops/pkg/featureflag" "k8s.io/kops/pkg/kubemanifest" "k8s.io/kops/pkg/values" @@ -45,6 +47,9 @@ type AssetBuilder struct { AssetsLocation *kops.Assets // TODO we'd like to use cloudup.Phase here, but that introduces a go cyclic dependency Phase string + + // KubernetesVersion is the version of kubernetes we are installing + KubernetesVersion semver.Version } // ContainerAsset models a container's location. @@ -67,11 +72,20 @@ type FileAsset struct { } // NewAssetBuilder creates a new AssetBuilder. -func NewAssetBuilder(assets *kops.Assets, phase string) *AssetBuilder { - return &AssetBuilder{ - AssetsLocation: assets, +func NewAssetBuilder(cluster *kops.Cluster, phase string) *AssetBuilder { + a := &AssetBuilder{ + AssetsLocation: cluster.Spec.Assets, Phase: phase, } + + version, err := util.ParseKubernetesVersion(cluster.Spec.KubernetesVersion) + if err != nil { + // This should have already been validated + glog.Fatalf("unexpected error from ParseKubernetesVersion %s: %v", cluster.Spec.KubernetesVersion, err) + } + a.KubernetesVersion = *version + + return a } // RemapManifest transforms a kubernetes manifest. @@ -112,6 +126,15 @@ func (a *AssetBuilder) RemapImage(image string) (string, error) { asset.DockerImage = image + // The k8s.gcr.io prefix is an alias, but for CI builds we run from a docker load, + // and we only double-tag from 1.10 onwards. + // For versions prior to 1.10, remap k8s.gcr.io to the old name. + // This also means that we won't start using the aliased names on existing clusters, + // which could otherwise be surprising to users. + if !util.IsKubernetesGTE("1.10", a.KubernetesVersion) && strings.HasPrefix(image, "k8s.gcr.io/") { + image = "gcr.io/google_containers/" + strings.TrimPrefix(image, "k8s.gcr.io/") + } + if strings.HasPrefix(image, "kope/dns-controller:") { // To use user-defined DNS Controller: // 1. DOCKER_REGISTRY=[your docker hub repo] make dns-controller-push diff --git a/tests/integration/update_cluster/additional_user-data/cloudformation.json.extracted.yaml b/tests/integration/update_cluster/additional_user-data/cloudformation.json.extracted.yaml index 7ee73bd08f..5b1a2eeb71 100644 --- a/tests/integration/update_cluster/additional_user-data/cloudformation.json.extracted.yaml +++ b/tests/integration/update_cluster/additional_user-data/cloudformation.json.extracted.yaml @@ -159,10 +159,10 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersadditionaluserda encryptionConfig: null etcdClusters: events: - image: k8s.gcr.io/etcd:2.2.1 + image: gcr.io/google_containers/etcd:2.2.1 version: 2.2.1 main: - image: k8s.gcr.io/etcd:2.2.1 + image: gcr.io/google_containers/etcd:2.2.1 version: 2.2.1 kubeAPIServer: address: 127.0.0.1 @@ -181,7 +181,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersadditionaluserda - http://127.0.0.1:4001 etcdServersOverrides: - /events#http://127.0.0.1:4002 - image: k8s.gcr.io/kube-apiserver:v1.4.12 + image: gcr.io/google_containers/kube-apiserver:v1.4.12 insecurePort: 8080 logLevel: 2 securePort: 443 @@ -194,7 +194,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersadditionaluserda clusterCIDR: 100.96.0.0/11 clusterName: additionaluserdata.example.com configureCloudRoutes: true - image: k8s.gcr.io/kube-controller-manager:v1.4.12 + image: gcr.io/google_containers/kube-controller-manager:v1.4.12 leaderElection: leaderElect: true logLevel: 2 @@ -204,10 +204,10 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersadditionaluserda cpuRequest: 100m featureGates: null hostnameOverride: '@aws' - image: k8s.gcr.io/kube-proxy:v1.4.12 + image: gcr.io/google_containers/kube-proxy:v1.4.12 logLevel: 2 kubeScheduler: - image: k8s.gcr.io/kube-scheduler:v1.4.12 + image: gcr.io/google_containers/kube-scheduler:v1.4.12 leaderElection: leaderElect: true logLevel: 2 @@ -227,7 +227,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersadditionaluserda networkPluginMTU: 9001 networkPluginName: kubenet nonMasqueradeCIDR: 100.64.0.0/10 - podInfraContainerImage: k8s.gcr.io/pause-amd64:3.0 + podInfraContainerImage: gcr.io/google_containers/pause-amd64:3.0 podManifestPath: /etc/kubernetes/manifests reconcileCIDR: true masterKubelet: @@ -246,7 +246,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersadditionaluserda networkPluginName: kubenet nonMasqueradeCIDR: 100.64.0.0/10 podCIDR: 10.123.45.0/28 - podInfraContainerImage: k8s.gcr.io/pause-amd64:3.0 + podInfraContainerImage: gcr.io/google_containers/pause-amd64:3.0 podManifestPath: /etc/kubernetes/manifests reconcileCIDR: true registerSchedulable: false @@ -459,7 +459,7 @@ Resources.AWSAutoScalingLaunchConfigurationnodesadditionaluserdataexamplecom.Pro cpuRequest: 100m featureGates: null hostnameOverride: '@aws' - image: k8s.gcr.io/kube-proxy:v1.4.12 + image: gcr.io/google_containers/kube-proxy:v1.4.12 logLevel: 2 kubelet: allowPrivileged: true @@ -476,7 +476,7 @@ Resources.AWSAutoScalingLaunchConfigurationnodesadditionaluserdataexamplecom.Pro networkPluginMTU: 9001 networkPluginName: kubenet nonMasqueradeCIDR: 100.64.0.0/10 - podInfraContainerImage: k8s.gcr.io/pause-amd64:3.0 + podInfraContainerImage: gcr.io/google_containers/pause-amd64:3.0 podManifestPath: /etc/kubernetes/manifests reconcileCIDR: true diff --git a/tests/integration/update_cluster/minimal-cloudformation/cloudformation.json.extracted.yaml b/tests/integration/update_cluster/minimal-cloudformation/cloudformation.json.extracted.yaml index d00a023ed7..fd72e92acb 100644 --- a/tests/integration/update_cluster/minimal-cloudformation/cloudformation.json.extracted.yaml +++ b/tests/integration/update_cluster/minimal-cloudformation/cloudformation.json.extracted.yaml @@ -150,10 +150,10 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersminimalexampleco encryptionConfig: null etcdClusters: events: - image: k8s.gcr.io/etcd:2.2.1 + image: gcr.io/google_containers/etcd:2.2.1 version: 2.2.1 main: - image: k8s.gcr.io/etcd:2.2.1 + image: gcr.io/google_containers/etcd:2.2.1 version: 2.2.1 kubeAPIServer: address: 127.0.0.1 @@ -172,7 +172,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersminimalexampleco - http://127.0.0.1:4001 etcdServersOverrides: - /events#http://127.0.0.1:4002 - image: k8s.gcr.io/kube-apiserver:v1.4.12 + image: gcr.io/google_containers/kube-apiserver:v1.4.12 insecurePort: 8080 logLevel: 2 securePort: 443 @@ -185,7 +185,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersminimalexampleco clusterCIDR: 100.96.0.0/11 clusterName: minimal.example.com configureCloudRoutes: true - image: k8s.gcr.io/kube-controller-manager:v1.4.12 + image: gcr.io/google_containers/kube-controller-manager:v1.4.12 leaderElection: leaderElect: true logLevel: 2 @@ -195,10 +195,10 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersminimalexampleco cpuRequest: 100m featureGates: null hostnameOverride: '@aws' - image: k8s.gcr.io/kube-proxy:v1.4.12 + image: gcr.io/google_containers/kube-proxy:v1.4.12 logLevel: 2 kubeScheduler: - image: k8s.gcr.io/kube-scheduler:v1.4.12 + image: gcr.io/google_containers/kube-scheduler:v1.4.12 leaderElection: leaderElect: true logLevel: 2 @@ -218,7 +218,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersminimalexampleco networkPluginMTU: 9001 networkPluginName: kubenet nonMasqueradeCIDR: 100.64.0.0/10 - podInfraContainerImage: k8s.gcr.io/pause-amd64:3.0 + podInfraContainerImage: gcr.io/google_containers/pause-amd64:3.0 podManifestPath: /etc/kubernetes/manifests reconcileCIDR: true masterKubelet: @@ -237,7 +237,7 @@ Resources.AWSAutoScalingLaunchConfigurationmasterustest1amastersminimalexampleco networkPluginName: kubenet nonMasqueradeCIDR: 100.64.0.0/10 podCIDR: 10.123.45.0/28 - podInfraContainerImage: k8s.gcr.io/pause-amd64:3.0 + podInfraContainerImage: gcr.io/google_containers/pause-amd64:3.0 podManifestPath: /etc/kubernetes/manifests reconcileCIDR: true registerSchedulable: false @@ -429,7 +429,7 @@ Resources.AWSAutoScalingLaunchConfigurationnodesminimalexamplecom.Properties.Use cpuRequest: 100m featureGates: null hostnameOverride: '@aws' - image: k8s.gcr.io/kube-proxy:v1.4.12 + image: gcr.io/google_containers/kube-proxy:v1.4.12 logLevel: 2 kubelet: allowPrivileged: true @@ -446,7 +446,7 @@ Resources.AWSAutoScalingLaunchConfigurationnodesminimalexamplecom.Properties.Use networkPluginMTU: 9001 networkPluginName: kubenet nonMasqueradeCIDR: 100.64.0.0/10 - podInfraContainerImage: k8s.gcr.io/pause-amd64:3.0 + podInfraContainerImage: gcr.io/google_containers/pause-amd64:3.0 podManifestPath: /etc/kubernetes/manifests reconcileCIDR: true