-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ [CABPK] Support using kubeadm v1beta2 types internally #4292
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:release-0.3
from
fabriziopandini:kubeadm-types-stop-gap
Mar 17, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
. "github.com/onsi/gomega" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta2" | ||
) | ||
|
||
func Test_KubeVersionToKubeadmAPIGroupVersion(t *testing.T) { | ||
type args struct { | ||
k8sVersion string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want schema.GroupVersion | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "fails when kubernetes version is too old", | ||
args: args{ | ||
k8sVersion: "v1.12.0", | ||
}, | ||
want: schema.GroupVersion{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "pass with minimum kubernetes version for kubeadm API v1beta1", | ||
args: args{ | ||
k8sVersion: "v1.13.0", | ||
}, | ||
want: GroupVersion, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "pass with kubernetes version for kubeadm API v1beta1", | ||
args: args{ | ||
k8sVersion: "v1.14.99", | ||
}, | ||
want: GroupVersion, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "pass with minimum kubernetes version for kubeadm API v1beta2", | ||
args: args{ | ||
k8sVersion: "v1.15.0", | ||
}, | ||
want: v1beta2.GroupVersion, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "pass with kubernetes version for kubeadm API v1beta2", | ||
args: args{ | ||
k8sVersion: "v1.20.99", | ||
}, | ||
want: v1beta2.GroupVersion, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "pass with future kubernetes version", | ||
args: args{ | ||
k8sVersion: "v99.99.99", | ||
}, | ||
want: v1beta2.GroupVersion, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
got, err := KubeVersionToKubeadmAPIGroupVersion(tt.args.k8sVersion) | ||
if tt.wantErr { | ||
g.Expect(err).To(HaveOccurred()) | ||
return | ||
} | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(got).To(Equal(tt.want)) | ||
}) | ||
} | ||
} | ||
|
||
func TestConfigurationToYAMLForVersion(t *testing.T) { | ||
type args struct { | ||
obj *ClusterConfiguration | ||
k8sVersion string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Generates a v1beta1 kubeadm configuration with Kubernetes versions < 1.15", | ||
args: args{ | ||
obj: &ClusterConfiguration{}, | ||
k8sVersion: "v1.14.9", | ||
}, | ||
want: "apiServer: {}\n" + | ||
"apiVersion: kubeadm.k8s.io/v1beta1\n" + "" + | ||
"controllerManager: {}\n" + | ||
"dns: {}\n" + | ||
"etcd: {}\n" + | ||
"kind: ClusterConfiguration\n" + | ||
"networking: {}\n" + | ||
"scheduler: {}\n", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Generates a v1beta2 kubeadm configuration with Kubernetes versions >= 1.15", | ||
args: args{ | ||
obj: &ClusterConfiguration{}, | ||
k8sVersion: "v1.15.0", | ||
}, | ||
want: "apiServer: {}\n" + | ||
"apiVersion: kubeadm.k8s.io/v1beta2\n" + "" + | ||
"controllerManager: {}\n" + | ||
"dns: {}\n" + | ||
"etcd: {}\n" + | ||
"kind: ClusterConfiguration\n" + | ||
"networking: {}\n" + | ||
"scheduler: {}\n", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
got, err := ConfigurationToYAMLForVersion(tt.args.obj, tt.args.k8sVersion) | ||
if tt.wantErr { | ||
g.Expect(err).To(HaveOccurred()) | ||
return | ||
} | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(got).To(Equal(tt.want), cmp.Diff(tt.want, got)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta2 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "kubeadm.k8s.io", Version: "v1beta2"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off topic:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see https://cluster-api.sigs.k8s.io/reference/versions.html
With this change CABPK will error out for Kubernetes < v1.13, while before things were failing in the cloud init script (which is much more complex to debug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move the checks above to a validation webhook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will open an issue to discuss this improvement.
The problem here is that this is a CABPK limitation, but the version could be defined on another resource (e.g. Machine deployments)
For the sake of this PR this is a little bit out of topic and this will also deviate from the original PR we are back porting.
Nevertheless we are already improving the status quo, so I hop this should not be a blocker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rif #4321