Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Jan 4, 2023
1 parent 9da8b5b commit e7fd985
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/blang/semver"
Expand All @@ -33,7 +34,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"

bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/util/kubeadm"
"sigs.k8s.io/cluster-api/internal/util/kubeadm"
"sigs.k8s.io/cluster-api/util/container"
"sigs.k8s.io/cluster-api/util/version"
)
Expand Down Expand Up @@ -617,15 +618,16 @@ func (in *KubeadmControlPlane) validateVersion(previousVersion string) (allErrs
)
}

if in.Spec.KubeadmConfigSpec.ClusterConfiguration != nil &&
// FIXME(later): enable again after all cases have been green in e2e tests before.
if os.Getenv("ENABLE_VALIDATION") == "true" && in.Spec.KubeadmConfigSpec.ClusterConfiguration != nil &&
in.Spec.KubeadmConfigSpec.ClusterConfiguration.ImageRepository == "" {
if toVersion.GTE(kubeadm.MinKubernetesVersionImageRegistryMigration) &&
toVersion.LT(kubeadm.NextKubernetesVersionImageRegistryMigration) {
if kubeadm.GetDefaultRegistry(toVersion) == kubeadm.OldKubernetesImageRepository {
allErrs = append(allErrs,
field.Forbidden(
field.NewPath("spec", "version"),
fmt.Sprintf("cannot upgrade to a Kubernetes (kubeadm) version which is using the old default registry. Please use a newer Kubernetes patch release which is using the new default registry (>= v1.22.17, >= v1.23.15, >= v1.24.9"),
"cannot upgrade to a Kubernetes (kubeadm) version which is using the old default registry. Please use a newer Kubernetes patch release which is using the new default registry (>= v1.22.17, >= v1.23.15, >= v1.24.9",
),
)
}
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
kubeadmtypes "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/proxy"
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/util/kubeadm"
"sigs.k8s.io/cluster-api/internal/util/kubeadm"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/certs"
containerutil "sigs.k8s.io/cluster-api/util/container"
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/workload_cluster_coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/util/kubeadm"
"sigs.k8s.io/cluster-api/internal/util/kubeadm"
containerutil "sigs.k8s.io/cluster-api/util/container"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package kubeadm contains utils related to kubeadm.
package kubeadm

import "github.com/blang/semver"
Expand All @@ -35,8 +36,8 @@ var (
NextKubernetesVersionImageRegistryMigration = semver.MustParse("1.26.0")
)

// GetDefaultRegistry returns the default registry of the given kubeadm version.
func GetDefaultRegistry(version semver.Version) string {

// If version <= v1.22.16 return k8s.gcr.io
if version.LTE(semver.MustParse("1.22.16")) {
return OldKubernetesImageRepository
Expand Down
13 changes: 4 additions & 9 deletions test/framework/daemonset_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/cluster-api/internal/util/kubeadm"
containerutil "sigs.k8s.io/cluster-api/util/container"
)

Expand All @@ -42,15 +43,9 @@ func WaitForKubeProxyUpgrade(ctx context.Context, input WaitForKubeProxyUpgradeI
parsedVersion, err := semver.ParseTolerant(input.KubernetesVersion)
Expect(err).ToNot(HaveOccurred())

// Beginning with kubernetes v1.22, kubernetes images including kube-proxy get published to registry.k8s.io.
// This ensures that the imageRepository setting gets patched to registry.k8s.io when upgrading from v1.21 or lower,
// but only if there was no imageRepository explicitly set at the KubeadmControlPlanes ClusterConfiguration.
// This follows the behavior of `kubeadm upgrade`.
wantKubeProxyRegistry := "registry.k8s.io"
if parsedVersion.LT(semver.Version{Major: 1, Minor: 22, Patch: 0, Pre: []semver.PRVersion{{VersionStr: "alpha"}}}) {
wantKubeProxyRegistry = "k8s.gcr.io"
}
wantKubeProxyImage := wantKubeProxyRegistry + "/kube-proxy:" + containerutil.SemverToOCIImageTag(input.KubernetesVersion)
// Validate the kube-proxy image according to how KCP sets the image in the kube-proxy DaemonSet.
// KCP does this based on the default registry of the Kubernetes (kubeadm) version.
wantKubeProxyImage := kubeadm.GetDefaultRegistry(parsedVersion) + "/kube-proxy:" + containerutil.SemverToOCIImageTag(input.KubernetesVersion)

Eventually(func() (bool, error) {
ds := &appsv1.DaemonSet{}
Expand Down

0 comments on commit e7fd985

Please sign in to comment.