Skip to content

Commit

Permalink
remove DNS type from api v1alpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
ludusrusso committed Apr 24, 2021
1 parent 1b4faf5 commit ca725f2
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 74 deletions.
16 changes: 13 additions & 3 deletions bootstrap/kubeadm/api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

Expand All @@ -42,15 +43,17 @@ func TestFuzzyConversion(t *testing.T) {
FuzzerFuncs: []fuzzer.FuzzerFuncs{KubeadmConfigStatusFuzzFuncs},
}))
t.Run("for KubeadmConfigTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1alpha4.KubeadmConfigTemplate{},
Spoke: &KubeadmConfigTemplate{},
Scheme: scheme,
Hub: &v1alpha4.KubeadmConfigTemplate{},
Spoke: &KubeadmConfigTemplate{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{KubeadmConfigStatusFuzzFuncs},
}))
}

func KubeadmConfigStatusFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
KubeadmConfigStatusFuzzer,
joinDNSFuzzer,
}
}

Expand All @@ -60,3 +63,10 @@ func KubeadmConfigStatusFuzzer(obj *KubeadmConfigStatus, c fuzz.Continue) {
// KubeadmConfigStatus.BootstrapData has been removed in v1alpha4, so setting it to nil in order to avoid v1alpha3 --> v1alpha4 --> v1alpha3 round trip errors.
obj.BootstrapData = nil
}

func joinDNSFuzzer(obj *v1beta1.DNS, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// DNS.Type does not exists in v1alpha4, so setting it to empty string in order to avoid v1alpha3 --> v1alpha4 --> v1alpha3 round trip errors.
obj.Type = "CoreDNS"
}
95 changes: 91 additions & 4 deletions bootstrap/kubeadm/api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions bootstrap/kubeadm/api/v1alpha4/kubeadm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ const (

// DNS defines the DNS addon that should be used in the cluster.
type DNS struct {
// Type defines the DNS add-on to be used
// +optional
Type DNSAddOnType `json:"type,omitempty"`

// ImageMeta allows to customize the image used for the DNS component
ImageMeta `json:",inline"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,6 @@ spec:
imageTag:
description: ImageTag allows to specify a tag for the image. In case this value is set, kubeadm does not change automatically the version of the above components during upgrades.
type: string
type:
description: Type defines the DNS add-on to be used
type: string
type: object
etcd:
description: 'Etcd holds configuration for etcd. NB: This value defaults to a Local (stacked) etcd'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,6 @@ spec:
imageTag:
description: ImageTag allows to specify a tag for the image. In case this value is set, kubeadm does not change automatically the version of the above components during upgrades.
type: string
type:
description: Type defines the DNS add-on to be used
type: string
type: object
etcd:
description: 'Etcd holds configuration for etcd. NB: This value defaults to a Local (stacked) etcd'
Expand Down
20 changes: 20 additions & 0 deletions bootstrap/kubeadm/types/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ package v1beta1
import (
"testing"

fuzz "github.com/google/gofuzz"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/runtime"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)
Expand All @@ -37,26 +40,43 @@ func TestFuzzyConversion(t *testing.T) {
Spoke: &ClusterConfiguration{},
// NOTE: Kubeadm types does not have ObjectMeta, so we are required to skip data annotation cleanup in the spoke-hub-spoke round trip test.
SkipSpokeAnnotationCleanup: true,
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))
t.Run("for ClusterStatus", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1alpha4.ClusterStatus{},
Spoke: &ClusterStatus{},
// NOTE: Kubeadm types does not have ObjectMeta, so we are required to skip data annotation cleanup in the spoke-hub-spoke round trip test.
SkipSpokeAnnotationCleanup: true,
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))
t.Run("for InitConfiguration", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1alpha4.InitConfiguration{},
Spoke: &InitConfiguration{},
// NOTE: Kubeadm types does not have ObjectMeta, so we are required to skip data annotation cleanup in the spoke-hub-spoke round trip test.
SkipSpokeAnnotationCleanup: true,
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))
t.Run("for JoinConfiguration", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1alpha4.JoinConfiguration{},
Spoke: &JoinConfiguration{},
// NOTE: Kubeadm types does not have ObjectMeta, so we are required to skip data annotation cleanup in the spoke-hub-spoke round trip test.
SkipSpokeAnnotationCleanup: true,
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))
}

func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
joinDNSFuzzer,
}
}

func joinDNSFuzzer(obj *DNS, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// DNS.Type does not exists in v1alpha4, so setting it to empty string in order to avoid v1beta2 --> v1alpha4 --> v1beta2 round trip errors.
obj.Type = ""
}
13 changes: 6 additions & 7 deletions bootstrap/kubeadm/types/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bootstrap/kubeadm/types/v1beta2/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
nodeRegistrationOptionsFuzzer,
initConfigurationFuzzer,
joinControlPlanesFuzzer,
joinDNSFuzzer,
}
}

Expand All @@ -97,3 +98,10 @@ func initConfigurationFuzzer(obj *InitConfiguration, c fuzz.Continue) {
// InitConfiguration.CertificateKey does not exists in v1alpha4, so setting it to empty string in order to avoid v1beta2 --> v1alpha4 --> v1beta2 round trip errors.
obj.CertificateKey = ""
}

func joinDNSFuzzer(obj *DNS, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// DNS.Type does not exists in v1alpha4, so setting it to empty string in order to avoid v1beta2 --> v1alpha4 --> v1beta2 round trip errors.
obj.Type = ""
}
12 changes: 5 additions & 7 deletions bootstrap/kubeadm/types/v1beta2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions controlplane/kubeadm/api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
kubeadmBootstrapTokenStringFuzzer,
cabpkBootstrapTokenStringFuzzer,
kubeadmBookstrapDNSFuzzer,
}
}

Expand All @@ -70,3 +71,7 @@ func cabpkBootstrapTokenStringFuzzer(in *cabpkv1.BootstrapTokenString, c fuzz.Co
in.ID = "abcdef"
in.Secret = "abcdef0123456789"
}

func kubeadmBookstrapDNSFuzzer(in *kubeadmv1beta1.DNS, c fuzz.Continue) {
in.Type = "kube-dns"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation/field"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
"sigs.k8s.io/cluster-api/util/container"
"sigs.k8s.io/cluster-api/util/version"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -356,10 +355,6 @@ func (in *KubeadmControlPlane) validateCoreDNSVersion(prev *KubeadmControlPlane)
return allErrs
}
targetDNS := &in.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS
//return if the type is anything other than empty (default), or CoreDNS.
if targetDNS.Type != "" && targetDNS.Type != bootstrapv1.CoreDNS {
return allErrs
}

fromVersion, err := version.ParseMajorMinorPatchTolerant(prev.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS.ImageTag)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,6 @@ spec:
imageTag:
description: ImageTag allows to specify a tag for the image. In case this value is set, kubeadm does not change automatically the version of the above components during upgrades.
type: string
type:
description: Type defines the DNS add-on to be used
type: string
type: object
etcd:
description: 'Etcd holds configuration for etcd. NB: This value defaults to a Local (stacked) etcd'
Expand Down
1 change: 0 additions & 1 deletion controlplane/kubeadm/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@ func TestKubeadmControlPlaneReconciler_updateCoreDNS(t *testing.T) {
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
ClusterConfiguration: &bootstrapv1.ClusterConfiguration{
DNS: bootstrapv1.DNS{
Type: bootstrapv1.CoreDNS,
ImageMeta: bootstrapv1.ImageMeta{
ImageRepository: "k8s.gcr.io",
ImageTag: "1.7.2",
Expand Down
4 changes: 0 additions & 4 deletions controlplane/kubeadm/internal/workload_cluster_coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ func (w *Workload) UpdateCoreDNS(ctx context.Context, kcp *controlplanev1.Kubead
}

clusterConfig := kcp.Spec.KubeadmConfigSpec.ClusterConfiguration
// Return early if the type is anything other than empty (default), or CoreDNS.
if clusterConfig.DNS.Type != "" && clusterConfig.DNS.Type != bootstrapv1.CoreDNS {
return nil
}

// Get the CoreDNS info needed for the upgrade.
info, err := w.getCoreDNSInfo(ctx, clusterConfig)
Expand Down
Loading

0 comments on commit ca725f2

Please sign in to comment.