Skip to content

Commit

Permalink
Merge pull request #4516 from ludusrusso/issue/4177
Browse files Browse the repository at this point in the history
⚠️ remove DNS type from v1alpha4
  • Loading branch information
k8s-ci-robot authored Apr 28, 2021
2 parents b53bae0 + a0186d2 commit 0beb260
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 84 deletions.
12 changes: 12 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha3
import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
kubeadmbootstrapv1alpha4 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
kubeadmbootstrapv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

Expand Down Expand Up @@ -75,3 +76,14 @@ func Convert_v1alpha3_KubeadmConfigStatus_To_v1alpha4_KubeadmConfigStatus(in *Ku
// KubeadmConfigStatus.BootstrapData has been removed in v1alpha4 because its content has been moved to the bootstrap data secret, value will be lost during conversion.
return autoConvert_v1alpha3_KubeadmConfigStatus_To_v1alpha4_KubeadmConfigStatus(in, out, s)
}

func Convert_v1alpha4_ClusterConfiguration_To_v1beta1_ClusterConfiguration(in *kubeadmbootstrapv1alpha4.ClusterConfiguration, out *kubeadmbootstrapv1beta1.ClusterConfiguration, s apiconversion.Scope) error {
// DNS.Type was removed in v1alpha4 because only CoreDNS is supported; the information will be left to empty (kubeadm defaults it to CoredDNS);
// Existing clusters using kube-dns or other DNS solutions will continue to be managed/supported via the skip-coredns annotation.
return kubeadmbootstrapv1beta1.Convert_v1alpha4_ClusterConfiguration_To_v1beta1_ClusterConfiguration(in, out, s)
}

func Convert_v1beta1_ClusterConfiguration_To_v1alpha4_ClusterConfiguration(in *kubeadmbootstrapv1beta1.ClusterConfiguration, out *kubeadmbootstrapv1alpha4.ClusterConfiguration, s apiconversion.Scope) error {
// DNS.Type was removed in v1alpha4 because only CoreDNS is supported, dropping this info.
return kubeadmbootstrapv1beta1.Convert_v1beta1_ClusterConfiguration_To_v1alpha4_ClusterConfiguration(in, out, s)
}
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,
dnsFuzzer,
}
}

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 dnsFuzzer(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 = ""
}
54 changes: 50 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 @@ -1171,9 +1171,6 @@ spec:
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,9 +1174,6 @@ spec:
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
Expand Down
6 changes: 6 additions & 0 deletions bootstrap/kubeadm/types/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -68,3 +69,8 @@ func (dst *JoinConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*bootstrapv1.JoinConfiguration)
return Convert_v1alpha4_JoinConfiguration_To_v1beta1_JoinConfiguration(src, dst, nil)
}

func Convert_v1beta1_DNS_To_v1alpha4_DNS(in *DNS, out *bootstrapv1.DNS, s apimachineryconversion.Scope) error {
// DNS.Type was removed in v1alpha4 because only CoreDNS is supported, dropping this info.
return autoConvert_v1beta1_DNS_To_v1alpha4_DNS(in, out, s)
}
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{}{
dnsFuzzer,
}
}

func dnsFuzzer(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 v1beta1 --> v1alpha4 --> v1beta1 round trip errors.
obj.Type = ""
}
18 changes: 6 additions & 12 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.

5 changes: 5 additions & 0 deletions bootstrap/kubeadm/types/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ func Convert_v1beta2_JoinControlPlane_To_v1alpha4_JoinControlPlane(in *JoinContr
// JoinControlPlane.CertificateKey exists in v1beta2 types but not in bootstrapv1.JoinControlPlane (Cluster API does not uses automatic copy certs). Ignoring when converting.
return autoConvert_v1beta2_JoinControlPlane_To_v1alpha4_JoinControlPlane(in, out, s)
}

func Convert_v1beta2_DNS_To_v1alpha4_DNS(in *DNS, out *bootstrapv1.DNS, s apimachineryconversion.Scope) error {
// DNS.Type was removed in v1alpha4 because only CoreDNS is supported, dropping this info.
return autoConvert_v1beta2_DNS_To_v1alpha4_DNS(in, out, s)
}
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,
dnsFuzzer,
}
}

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 dnsFuzzer(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 = ""
}
18 changes: 6 additions & 12 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.

8 changes: 8 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,
dnsFuzzer,
}
}

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

func dnsFuzzer(obj *kubeadmv1beta1.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 = ""
}
Loading

0 comments on commit 0beb260

Please sign in to comment.