Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit 9631566

Browse files
authored
Merge pull request #1427 from mesosphere/kind-kubernetes-upgrade
Kind and Kubernetes upgrade
2 parents 29a8171 + fc5b459 commit 9631566

File tree

12 files changed

+165
-13
lines changed

12 files changed

+165
-13
lines changed

charts/kubefed/Chart.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v2
22
description: KubeFed helm chart
33
name: kubefed
44
version: 0.0.3
5+
kubeVersion: ">= 1.16.0"
56
dependencies:
67
- name: controllermanager
78
version: 0.0.3

charts/kubefed/charts/controllermanager/templates/webhook.yaml

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{- $altName1 := printf "kubefed-admission-webhook.%s" .Release.Namespace }}
44
{{- $altName2 := printf "kubefed-admission-webhook.%s.svc" .Release.Namespace }}
55
{{- $cert := genSignedCert $cn nil (list $altName1 $altName2) 3650 $ca }}
6-
apiVersion: admissionregistration.k8s.io/v1beta1
6+
apiVersion: admissionregistration.k8s.io/v1
77
kind: ValidatingWebhookConfiguration
88
metadata:
99
# For namespace scoped deployments, create a unique cluster-scoped resource
@@ -19,6 +19,8 @@ metadata:
1919
{{- end }}
2020
webhooks:
2121
- name: federatedtypeconfigs.core.kubefed.io
22+
admissionReviewVersions:
23+
- v1
2224
clientConfig:
2325
service:
2426
namespace: {{ .Release.Namespace | quote }}
@@ -39,6 +41,7 @@ webhooks:
3941
- federatedtypeconfigs
4042
- federatedtypeconfigs/status
4143
failurePolicy: Fail
44+
sideEffects: None
4245
{{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }}
4346
# For namespace scoped deployments: filter admission webhook requests for
4447
# resources whose namespace matches the default namespace label applied by helm
@@ -51,6 +54,8 @@ webhooks:
5154
name: {{ .Release.Namespace }}
5255
{{ end }}
5356
- name: kubefedclusters.core.kubefed.io
57+
admissionReviewVersions:
58+
- v1
5459
clientConfig:
5560
service:
5661
namespace: {{ .Release.Namespace | quote }}
@@ -71,13 +76,16 @@ webhooks:
7176
- kubefedclusters
7277
- kubefedclusters/status
7378
failurePolicy: Fail
79+
sideEffects: None
7480
{{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }}
7581
# See comment above.
7682
namespaceSelector:
7783
matchLabels:
7884
name: {{ .Release.Namespace }}
7985
{{ end }}
8086
- name: kubefedconfigs.core.kubefed.io
87+
admissionReviewVersions:
88+
- v1
8189
clientConfig:
8290
service:
8391
namespace: {{ .Release.Namespace | quote }}
@@ -97,6 +105,7 @@ webhooks:
97105
resources:
98106
- kubefedconfigs
99107
failurePolicy: Fail
108+
sideEffects: None
100109
{{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }}
101110
# See comment above.
102111
namespaceSelector:
@@ -106,7 +115,7 @@ webhooks:
106115
---
107116
# The same comments for ValidatingWebhookConfiguration apply here to
108117
# MutatingWebhookConfiguration.
109-
apiVersion: admissionregistration.k8s.io/v1beta1
118+
apiVersion: admissionregistration.k8s.io/v1
110119
kind: MutatingWebhookConfiguration
111120
metadata:
112121
{{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }}
@@ -116,6 +125,8 @@ metadata:
116125
{{- end }}
117126
webhooks:
118127
- name: kubefedconfigs.core.kubefed.io
128+
admissionReviewVersions:
129+
- v1
119130
clientConfig:
120131
service:
121132
namespace: {{ .Release.Namespace | quote }}
@@ -134,6 +145,7 @@ webhooks:
134145
resources:
135146
- kubefedconfigs
136147
failurePolicy: Fail
148+
sideEffects: None
137149
{{- if and .Values.global.scope (eq .Values.global.scope "Namespaced") }}
138150
namespaceSelector:
139151
matchLabels:

docs/development.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ help you get started.
3434
### Binaries
3535

3636
The KubeFed deployment depends on `kubebuilder`, `etcd`, `kubectl`, and
37-
`kube-apiserver` >= v1.13 being installed in the path. The `kubebuilder`
37+
`kube-apiserver` >= v1.16 being installed in the path. The `kubebuilder`
3838
([v2.3.1](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/v2.3.1)
3939
as of this writing) release packages all of these dependencies together.
4040

@@ -48,7 +48,7 @@ export PATH=$(pwd)/bin:${PATH}
4848

4949
### kubernetes
5050

51-
The KubeFed deployment requires kubernetes version >= 1.13. To see a detailed list of binaries required, see the prerequisites section in the [user guide](./userguide.md#prerequisites)
51+
The KubeFed deployment requires kubernetes version >= 1.16. To see a detailed list of binaries required, see the prerequisites section in the [user guide](./userguide.md#prerequisites)
5252

5353
## Prerequisites
5454

docs/environments/kind.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ script if you'd like to change the default:
4343
NUM_CLUSTERS=<num> ./scripts/create-clusters.sh
4444
```
4545

46-
The `KIND_TAG` is `v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b` by default.
47-
Image `kindest/node:v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b` is used as
46+
The `KIND_TAG` is `v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6` by default.
47+
Image `kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6` is used as
4848
node docker image for booting the cluster.
4949

5050
You can use `KIND_IMAGE` or `KIND_TAG` to specify the image as you want.
5151
```bash
52-
KIND_TAG=v1.18.8 ./scripts/create-clusters.sh
52+
KIND_TAG=v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b ./scripts/create-clusters.sh
5353
```
5454

5555
```bash
56-
KIND_IMAGE=kindest/node:v1.18.8 ./scripts/create-clusters.sh
56+
KIND_IMAGE=kindest/node:v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b ./scripts/create-clusters.sh
5757
```
5858

5959
## Delete Clusters

pkg/controller/sync/dispatch/retain.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func retainServiceFields(desiredObj, clusterObj *unstructured.Unstructured) erro
5959

6060
// ClusterIP and NodePort are allocated to Service by cluster, so retain the same if any while updating
6161

62-
// Retain clusterip
62+
// Retain clusterip and clusterips
6363
clusterIP, ok, err := unstructured.NestedString(clusterObj.Object, "spec", "clusterIP")
6464
if err != nil {
6565
return errors.Wrap(err, "Error retrieving clusterIP from cluster service")
@@ -71,6 +71,17 @@ func retainServiceFields(desiredObj, clusterObj *unstructured.Unstructured) erro
7171
return errors.Wrap(err, "Error setting clusterIP for service")
7272
}
7373
}
74+
clusterIPs, ok, err := unstructured.NestedStringSlice(clusterObj.Object, "spec", "clusterIPs")
75+
if err != nil {
76+
return errors.Wrap(err, "Error retrieving clusterIPs from cluster service")
77+
}
78+
// !ok could indicate that cluster ips was not assigned
79+
if ok && len(clusterIPs) > 0 {
80+
err := unstructured.SetNestedStringSlice(desiredObj.Object, clusterIPs, "spec", "clusterIPs")
81+
if err != nil {
82+
return errors.Wrap(err, "Error setting clusterIPs for service")
83+
}
84+
}
7485

7586
// Retain nodeports
7687
clusterPorts, ok, err := unstructured.NestedSlice(clusterObj.Object, "spec", "ports")

pkg/controller/sync/dispatch/retain_test.go

+119
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package dispatch
1818

1919
import (
20+
"reflect"
2021
"testing"
2122

2223
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -171,3 +172,121 @@ func TestRetainHealthCheckNodePortInServiceFields(t *testing.T) {
171172
})
172173
}
173174
}
175+
176+
func TestRetainClusterIPsInServiceFields(t *testing.T) {
177+
tests := []struct {
178+
name string
179+
desiredObj *unstructured.Unstructured
180+
clusterObj *unstructured.Unstructured
181+
retainSucceed bool
182+
expectedClusterIPValue *string
183+
expectedClusterIPsValue []string
184+
}{
185+
{
186+
"cluster object has no clusterIP or clusterIPs",
187+
&unstructured.Unstructured{
188+
Object: map[string]interface{}{},
189+
},
190+
&unstructured.Unstructured{
191+
Object: map[string]interface{}{},
192+
},
193+
true,
194+
nil,
195+
nil,
196+
},
197+
{
198+
"cluster object has clusterIP",
199+
&unstructured.Unstructured{
200+
Object: map[string]interface{}{},
201+
},
202+
&unstructured.Unstructured{
203+
Object: map[string]interface{}{
204+
"spec": map[string]interface{}{
205+
"clusterIP": -1000,
206+
},
207+
},
208+
},
209+
false,
210+
nil,
211+
nil,
212+
},
213+
{
214+
"cluster object has clusterIP only",
215+
&unstructured.Unstructured{
216+
Object: map[string]interface{}{},
217+
},
218+
&unstructured.Unstructured{
219+
Object: map[string]interface{}{
220+
"spec": map[string]interface{}{
221+
"clusterIP": "1.2.3.4",
222+
},
223+
},
224+
},
225+
true,
226+
pointer.String("1.2.3.4"),
227+
nil,
228+
},
229+
{
230+
"cluster object has clusterIPs only",
231+
&unstructured.Unstructured{
232+
Object: map[string]interface{}{},
233+
},
234+
&unstructured.Unstructured{
235+
Object: map[string]interface{}{
236+
"spec": map[string]interface{}{
237+
"clusterIPs": []interface{}{"1.2.3.4", "5.6.7.8"},
238+
},
239+
},
240+
},
241+
true,
242+
nil,
243+
[]string{"1.2.3.4", "5.6.7.8"},
244+
},
245+
{
246+
"cluster object has both clusterIP and clusterIPs",
247+
&unstructured.Unstructured{
248+
Object: map[string]interface{}{},
249+
},
250+
&unstructured.Unstructured{
251+
Object: map[string]interface{}{
252+
"spec": map[string]interface{}{
253+
"clusterIP": "1.2.3.4",
254+
"clusterIPs": []interface{}{"5.6.7.8", "9.10.11.12"},
255+
},
256+
},
257+
},
258+
true,
259+
pointer.String("1.2.3.4"),
260+
[]string{"5.6.7.8", "9.10.11.12"},
261+
},
262+
}
263+
for _, test := range tests {
264+
t.Run(test.name, func(t *testing.T) {
265+
if err := retainServiceFields(test.desiredObj, test.clusterObj); (err == nil) != test.retainSucceed {
266+
t.Fatalf("test %s fails: unexpected returned error %v", test.name, err)
267+
}
268+
269+
currentClusterIPValue, ok, err := unstructured.NestedString(test.desiredObj.Object, "spec", "clusterIP")
270+
if err != nil {
271+
t.Fatalf("test %s fails: %v", test.name, err)
272+
}
273+
if !ok && test.expectedClusterIPValue != nil {
274+
t.Fatalf("test %s fails: expect specified clusterIP but not found", test.name)
275+
}
276+
if ok && (test.expectedClusterIPValue == nil || *test.expectedClusterIPValue != currentClusterIPValue) {
277+
t.Fatalf("test %s fails: unexpected current clusterIP %s", test.name, currentClusterIPValue)
278+
}
279+
280+
currentClusterIPsValue, ok, err := unstructured.NestedStringSlice(test.desiredObj.Object, "spec", "clusterIPs")
281+
if err != nil {
282+
t.Fatalf("test %s fails: %v", test.name, err)
283+
}
284+
if !ok && test.expectedClusterIPsValue != nil {
285+
t.Fatalf("test %s fails: expect specified clusterIPs but not found", test.name)
286+
}
287+
if ok && !reflect.DeepEqual(test.expectedClusterIPsValue, currentClusterIPsValue) {
288+
t.Fatalf("test %s fails: unexpected current clusterIPs %v", test.name, currentClusterIPsValue)
289+
}
290+
})
291+
}
292+
}

pkg/kubefedctl/federate/federate.go

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ func FederatedResourceFromTargetResource(typeConfig typeconfig.Interface, resour
390390
}
391391
}
392392
unstructured.RemoveNestedField(targetResource.Object, "spec", "clusterIP")
393+
unstructured.RemoveNestedField(targetResource.Object, "spec", "clusterIPs")
393394
}
394395
}
395396

pkg/schedulingtypes/replicascheduler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (s *ReplicaScheduler) Reconcile(obj runtimeclient.Object, qualifiedName ctl
198198

199199
resultClusters, err := plugin.(*Plugin).GetResourceClusters(qualifiedName, fedClusters)
200200
if err != nil {
201-
runtime.HandleError(errors.Wrapf(err, "Failed to get prefrerred clusters while reconciling RSP named %q", key))
201+
runtime.HandleError(errors.Wrapf(err, "Failed to get preferred clusters while reconciling RSP named %q", key))
202202
return ctlutil.StatusError
203203
}
204204

scripts/create-clusters.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set -o pipefail
2525
source "${BASH_SOURCE%/*}/util.sh"
2626
NUM_CLUSTERS="${NUM_CLUSTERS:-2}"
2727
KIND_IMAGE="${KIND_IMAGE:-}"
28-
KIND_TAG="${KIND_TAG:-v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b}"
28+
KIND_TAG="${KIND_TAG:-v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6}"
2929
OS="$(uname)"
3030

3131
function create-clusters() {

scripts/download-e2e-binaries.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mkdir -p "${dest_dir}"
3636

3737
# kind
3838
platform="$(uname -s|tr A-Z a-z)"
39-
kind_version="v0.9.0"
39+
kind_version="v0.11.1"
4040
kind_path="${dest_dir}/kind"
4141
kind_url="https://github.com/kubernetes-sigs/kind/releases/download/${kind_version}/kind-${platform}-amd64"
4242
curl -fLo "${kind_path}" "${kind_url}" && chmod +x "${kind_path}"

scripts/pre-commit.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ run-unit-tests
175175
echo "Downloading e2e test dependencies"
176176
./scripts/download-e2e-binaries.sh
177177

178-
KIND_TAG="v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b" ./scripts/create-clusters.sh
178+
KIND_TAG="v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6" ./scripts/create-clusters.sh
179179

180180
declare -a join_cluster_list=()
181181
if [[ -z "${JOIN_CLUSTERS}" ]]; then

test/common/crudtester.go

+8
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,14 @@ func (c *FederatedTypeCrudTester) waitForResource(client util.ResourceClient, qu
630630
c.tl.Fatalf("Failed to apply json patch: %v", err)
631631
}
632632

633+
// Kubernetes 1.21 introduced a label kubernetes.io/metadata.name to all namespaces so regardless of what we
634+
// override we should always add this label here to this check.
635+
if expectedClusterObject.GetObjectKind().GroupVersionKind() == apiv1.SchemeGroupVersion.WithKind("Namespace") {
636+
labels := expectedClusterObject.GetLabels()
637+
labels[apiv1.LabelMetadataName] = expectedClusterObject.GetName()
638+
expectedClusterObject.SetLabels(labels)
639+
}
640+
633641
expectedClusterObjectJSON, err := expectedClusterObject.MarshalJSON()
634642
if err != nil {
635643
c.tl.Fatalf("Failed to marshal expected cluster object to json: %v", err)

0 commit comments

Comments
 (0)