Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 4a25d74

Browse files
Patrick BaxterYifan Gu
authored andcommitted
cmd/checkpoint: 1.6.1 updates
1 parent 90ce2cb commit 4a25d74

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

cmd/checkpoint/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717

1818
"github.com/golang/glog"
1919

20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/fields"
22+
"k8s.io/apimachinery/pkg/runtime"
23+
"k8s.io/client-go/tools/clientcmd"
2024
"k8s.io/kubernetes/pkg/api"
21-
"k8s.io/kubernetes/pkg/api/unversioned"
2225
"k8s.io/kubernetes/pkg/api/v1"
23-
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5"
24-
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
25-
"k8s.io/kubernetes/pkg/fields"
26-
"k8s.io/kubernetes/pkg/runtime"
26+
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
2727
)
2828

2929
const (
@@ -408,7 +408,7 @@ func sanitizeCheckpointPod(cp *v1.Pod) (*v1.Pod, error) {
408408
// NOTE(aaron): If we want to keep labels, we need to add a new label so the static pod
409409
// will not be adopted by higher-level parent (e.g. daemonset/deployment).
410410
// Otherwise you end up in situations where parent tries deleting mirror pods.
411-
cp.ObjectMeta = v1.ObjectMeta{
411+
cp.ObjectMeta = metav1.ObjectMeta{
412412
Name: cp.Name,
413413
Namespace: cp.Namespace,
414414
Annotations: make(map[string]string),
@@ -462,7 +462,7 @@ func getFileCheckpoints(path string) map[string]*v1.Pod {
462462

463463
// getAPIParentPods will retrieve all pods from apiserver that are parents & should be checkpointed
464464
func getAPIParentPods(client clientset.Interface, nodeName string) map[string]*v1.Pod {
465-
opts := v1.ListOptions{
465+
opts := metav1.ListOptions{
466466
FieldSelector: fields.OneTermEqualSelector(api.PodHostField, nodeName).String(),
467467
}
468468

@@ -544,7 +544,7 @@ func checkpointSecretVolumes(client clientset.Interface, pod *v1.Pod) (*v1.Pod,
544544
// The path to the secret data becomes: checkpointSecretPath/namespace/podname/secretName/secret.file
545545
// Where each "secret.file" is a key from the secret.Data field.
546546
func checkpointSecret(client clientset.Interface, namespace, podName, secretName string) (string, error) {
547-
secret, err := client.Core().Secrets(namespace).Get(secretName)
547+
secret, err := client.Core().Secrets(namespace).Get(secretName, metav1.GetOptions{})
548548
if err != nil {
549549
return "", fmt.Errorf("failed to retrieve secret %s/%s: %v", namespace, secretName, err)
550550
}
@@ -585,7 +585,7 @@ func checkpointConfigMapVolumes(client clientset.Interface, pod *v1.Pod) (*v1.Po
585585
// The path to the configMap data becomes: checkpointSecretPath/namespace/podname/configMapName/configMap.file
586586
// Where each "configMap.file" is a key from the configMap.Data field.
587587
func checkpointConfigMap(client clientset.Interface, namespace, podName, configMapName string) (string, error) {
588-
configMap, err := client.Core().ConfigMaps(namespace).Get(configMapName)
588+
configMap, err := client.Core().ConfigMaps(namespace).Get(configMapName, metav1.GetOptions{})
589589
if err != nil {
590590
return "", fmt.Errorf("failed to retrieve configMap %s/%s: %v", namespace, configMapName, err)
591591
}
@@ -712,7 +712,7 @@ func podListToMap(pl *v1.PodList, filter filterFn) map[string]*v1.Pod {
712712

713713
// Pods from Kubelet API do not have TypeMeta populated - set it here either way.
714714
pods[id] = pod
715-
pods[id].TypeMeta = unversioned.TypeMeta{
715+
pods[id].TypeMeta = metav1.TypeMeta{
716716
APIVersion: pl.APIVersion,
717717
Kind: "Pod",
718718
}

cmd/checkpoint/main_test.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66
"testing"
77

8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
"k8s.io/kubernetes/pkg/api"
910
"k8s.io/kubernetes/pkg/api/v1"
1011
)
@@ -112,7 +113,7 @@ func TestProcess(t *testing.T) {
112113
apiParents: map[string]*v1.Pod{"kube-system/pod-checkpointer": {}},
113114
inactiveCheckpoints: map[string]*v1.Pod{
114115
"kube-system/pod-checkpointer": {
115-
ObjectMeta: v1.ObjectMeta{
116+
ObjectMeta: metav1.ObjectMeta{
116117
Namespace: "kube-system",
117118
Name: "pod-checkpointer",
118119
},
@@ -125,7 +126,7 @@ func TestProcess(t *testing.T) {
125126
localParents: map[string]*v1.Pod{"kube-system/pod-checkpointer": {}},
126127
inactiveCheckpoints: map[string]*v1.Pod{
127128
"kube-system/pod-checkpointer": {
128-
ObjectMeta: v1.ObjectMeta{
129+
ObjectMeta: metav1.ObjectMeta{
129130
Namespace: "kube-system",
130131
Name: "pod-checkpointer",
131132
},
@@ -140,7 +141,7 @@ func TestProcess(t *testing.T) {
140141
apiParents: map[string]*v1.Pod{"BB": {}},
141142
inactiveCheckpoints: map[string]*v1.Pod{
142143
"kube-system/pod-checkpointer": {
143-
ObjectMeta: v1.ObjectMeta{
144+
ObjectMeta: metav1.ObjectMeta{
144145
Namespace: "kube-system",
145146
Name: "pod-checkpointer",
146147
},
@@ -156,7 +157,7 @@ func TestProcess(t *testing.T) {
156157
apiParents: map[string]*v1.Pod{"AA": {}},
157158
inactiveCheckpoints: map[string]*v1.Pod{
158159
"kube-system/pod-checkpointer": {
159-
ObjectMeta: v1.ObjectMeta{
160+
ObjectMeta: metav1.ObjectMeta{
160161
Namespace: "kube-system",
161162
Name: "pod-checkpointer",
162163
},
@@ -172,7 +173,7 @@ func TestProcess(t *testing.T) {
172173
apiParents: map[string]*v1.Pod{"AA": {}},
173174
activeCheckpoints: map[string]*v1.Pod{
174175
"kube-system/pod-checkpointer": {
175-
ObjectMeta: v1.ObjectMeta{
176+
ObjectMeta: metav1.ObjectMeta{
176177
Namespace: "kube-system",
177178
Name: "pod-checkpointer",
178179
},
@@ -189,7 +190,7 @@ func TestProcess(t *testing.T) {
189190
apiParents: map[string]*v1.Pod{"kube-system/pod-checkpointer": {}},
190191
inactiveCheckpoints: map[string]*v1.Pod{
191192
"kube-system/pod-checkpointer": {
192-
ObjectMeta: v1.ObjectMeta{
193+
ObjectMeta: metav1.ObjectMeta{
193194
Namespace: "kube-system",
194195
Name: "pod-checkpointer",
195196
},
@@ -203,7 +204,7 @@ func TestProcess(t *testing.T) {
203204
localParents: map[string]*v1.Pod{"kube-system/pod-checkpointer": {}},
204205
inactiveCheckpoints: map[string]*v1.Pod{
205206
"kube-system/pod-checkpointer": {
206-
ObjectMeta: v1.ObjectMeta{
207+
ObjectMeta: metav1.ObjectMeta{
207208
Namespace: "kube-system",
208209
Name: "pod-checkpointer",
209210
},
@@ -219,7 +220,7 @@ func TestProcess(t *testing.T) {
219220
apiParents: map[string]*v1.Pod{"BB": {}},
220221
inactiveCheckpoints: map[string]*v1.Pod{
221222
"kube-system/pod-checkpointer": {
222-
ObjectMeta: v1.ObjectMeta{
223+
ObjectMeta: metav1.ObjectMeta{
223224
Namespace: "kube-system",
224225
Name: "pod-checkpointer",
225226
},
@@ -236,7 +237,7 @@ func TestProcess(t *testing.T) {
236237
apiParents: map[string]*v1.Pod{"AA": {}},
237238
inactiveCheckpoints: map[string]*v1.Pod{
238239
"kube-system/pod-checkpointer": {
239-
ObjectMeta: v1.ObjectMeta{
240+
ObjectMeta: metav1.ObjectMeta{
240241
Namespace: "kube-system",
241242
Name: "pod-checkpointer",
242243
},
@@ -253,7 +254,7 @@ func TestProcess(t *testing.T) {
253254
apiParents: map[string]*v1.Pod{"AA": {}},
254255
activeCheckpoints: map[string]*v1.Pod{
255256
"kube-system/pod-checkpointer": {
256-
ObjectMeta: v1.ObjectMeta{
257+
ObjectMeta: metav1.ObjectMeta{
257258
Namespace: "kube-system",
258259
Name: "pod-checkpointer",
259260
},
@@ -290,13 +291,13 @@ func TestSanitizeCheckpointPod(t *testing.T) {
290291
{
291292
desc: "Pod name and namespace are preserved & checkpoint annotation added",
292293
pod: &v1.Pod{
293-
ObjectMeta: v1.ObjectMeta{
294+
ObjectMeta: metav1.ObjectMeta{
294295
Name: "podname",
295296
Namespace: "podnamespace",
296297
},
297298
},
298299
expected: &v1.Pod{
299-
ObjectMeta: v1.ObjectMeta{
300+
ObjectMeta: metav1.ObjectMeta{
300301
Name: "podname",
301302
Namespace: "podnamespace",
302303
Annotations: map[string]string{checkpointParentAnnotation: "podname"},
@@ -306,14 +307,14 @@ func TestSanitizeCheckpointPod(t *testing.T) {
306307
{
307308
desc: "Existing annotations are removed, checkpoint annotation added",
308309
pod: &v1.Pod{
309-
ObjectMeta: v1.ObjectMeta{
310+
ObjectMeta: metav1.ObjectMeta{
310311
Name: "podname",
311312
Namespace: "podnamespace",
312313
Annotations: map[string]string{"foo": "bar"},
313314
},
314315
},
315316
expected: &v1.Pod{
316-
ObjectMeta: v1.ObjectMeta{
317+
ObjectMeta: metav1.ObjectMeta{
317318
Name: "podname",
318319
Namespace: "podnamespace",
319320
Annotations: map[string]string{checkpointParentAnnotation: "podname"},
@@ -323,14 +324,14 @@ func TestSanitizeCheckpointPod(t *testing.T) {
323324
{
324325
desc: "Pod status is reset",
325326
pod: &v1.Pod{
326-
ObjectMeta: v1.ObjectMeta{
327+
ObjectMeta: metav1.ObjectMeta{
327328
Name: "podname",
328329
Namespace: "podnamespace",
329330
},
330331
Status: v1.PodStatus{Phase: "Pending"},
331332
},
332333
expected: &v1.Pod{
333-
ObjectMeta: v1.ObjectMeta{
334+
ObjectMeta: metav1.ObjectMeta{
334335
Name: "podname",
335336
Namespace: "podnamespace",
336337
Annotations: map[string]string{checkpointParentAnnotation: "podname"},
@@ -340,14 +341,14 @@ func TestSanitizeCheckpointPod(t *testing.T) {
340341
{
341342
desc: "Service acounts are cleared",
342343
pod: &v1.Pod{
343-
ObjectMeta: v1.ObjectMeta{
344+
ObjectMeta: metav1.ObjectMeta{
344345
Name: "podname",
345346
Namespace: "podnamespace",
346347
},
347348
Spec: v1.PodSpec{ServiceAccountName: "foo", DeprecatedServiceAccount: "bar"},
348349
},
349350
expected: &v1.Pod{
350-
ObjectMeta: v1.ObjectMeta{
351+
ObjectMeta: metav1.ObjectMeta{
351352
Name: "podname",
352353
Namespace: "podnamespace",
353354
Annotations: map[string]string{checkpointParentAnnotation: "podname"},
@@ -368,10 +369,10 @@ func TestSanitizeCheckpointPod(t *testing.T) {
368369
}
369370

370371
func TestPodListToParentPods(t *testing.T) {
371-
parentAPod := v1.Pod{ObjectMeta: v1.ObjectMeta{Name: "A", Namespace: "A", Annotations: map[string]string{shouldCheckpointAnnotation: "true"}}}
372-
parentBPod := v1.Pod{ObjectMeta: v1.ObjectMeta{Name: "B", Namespace: "B", Annotations: map[string]string{shouldCheckpointAnnotation: "true"}}}
373-
checkpointPod := v1.Pod{ObjectMeta: v1.ObjectMeta{Name: "C", Namespace: "C", Annotations: map[string]string{checkpointParentAnnotation: "foo/bar"}}}
374-
regularPod := v1.Pod{ObjectMeta: v1.ObjectMeta{Name: "D", Namespace: "D", Annotations: map[string]string{"meta": "data"}}}
372+
parentAPod := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "A", Namespace: "A", Annotations: map[string]string{shouldCheckpointAnnotation: "true"}}}
373+
parentBPod := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "B", Namespace: "B", Annotations: map[string]string{shouldCheckpointAnnotation: "true"}}}
374+
checkpointPod := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "C", Namespace: "C", Annotations: map[string]string{checkpointParentAnnotation: "foo/bar"}}}
375+
regularPod := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "D", Namespace: "D", Annotations: map[string]string{"meta": "data"}}}
375376

376377
type testCase struct {
377378
desc string
@@ -470,7 +471,7 @@ func TestIsRunning(t *testing.T) {
470471

471472
func podWithAnnotations(a map[string]string) *v1.Pod {
472473
return &v1.Pod{
473-
ObjectMeta: v1.ObjectMeta{
474+
ObjectMeta: metav1.ObjectMeta{
474475
Name: "podname",
475476
Namespace: "podnamespace",
476477
Annotations: a,
@@ -548,7 +549,7 @@ func TestIsCheckpoint(t *testing.T) {
548549
{
549550
desc: fmt.Sprintf("Pod is checkpoint and contains %s annotation key and value", checkpointParentAnnotation),
550551
pod: &v1.Pod{
551-
ObjectMeta: v1.ObjectMeta{
552+
ObjectMeta: metav1.ObjectMeta{
552553
Annotations: map[string]string{checkpointParentAnnotation: "podnamespace/podname"},
553554
},
554555
},
@@ -557,7 +558,7 @@ func TestIsCheckpoint(t *testing.T) {
557558
{
558559
desc: fmt.Sprintf("Pod is checkpoint contains %s annotation key and no value", checkpointParentAnnotation),
559560
pod: &v1.Pod{
560-
ObjectMeta: v1.ObjectMeta{
561+
ObjectMeta: metav1.ObjectMeta{
561562
Annotations: map[string]string{checkpointParentAnnotation: ""},
562563
},
563564
},
@@ -566,7 +567,7 @@ func TestIsCheckpoint(t *testing.T) {
566567
{
567568
desc: "Pod is not checkpoint & contains unrelated annotations",
568569
pod: &v1.Pod{
569-
ObjectMeta: v1.ObjectMeta{
570+
ObjectMeta: metav1.ObjectMeta{
570571
Annotations: map[string]string{"foo": "bar"},
571572
},
572573
},
@@ -575,7 +576,7 @@ func TestIsCheckpoint(t *testing.T) {
575576
{
576577
desc: "Pod is not checkpoint & contains no annotations",
577578
pod: &v1.Pod{
578-
ObjectMeta: v1.ObjectMeta{},
579+
ObjectMeta: metav1.ObjectMeta{},
579580
},
580581
expected: false,
581582
},
@@ -591,7 +592,7 @@ func TestIsCheckpoint(t *testing.T) {
591592

592593
func TestCopyPod(t *testing.T) {
593594
pod := v1.Pod{
594-
ObjectMeta: v1.ObjectMeta{
595+
ObjectMeta: metav1.ObjectMeta{
595596
Name: "podname",
596597
Namespace: "podnamespace",
597598
},
@@ -608,7 +609,7 @@ func TestCopyPod(t *testing.T) {
608609

609610
func TestPodID(t *testing.T) {
610611
pod := &v1.Pod{
611-
ObjectMeta: v1.ObjectMeta{
612+
ObjectMeta: metav1.ObjectMeta{
612613
Name: "podname",
613614
Namespace: "podnamespace",
614615
},

0 commit comments

Comments
 (0)