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

Commit cf89a6d

Browse files
authored
Merge pull request #462 from diegs/checkpoint-clientgo
Switch checkpointer to use client-go.
2 parents 5f23e44 + ab882d1 commit cf89a6d

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

cmd/checkpoint/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/apimachinery/pkg/fields"
2222
"k8s.io/apimachinery/pkg/runtime"
23+
"k8s.io/client-go/kubernetes"
24+
"k8s.io/client-go/pkg/api"
25+
"k8s.io/client-go/pkg/api/v1"
2326
"k8s.io/client-go/tools/clientcmd"
24-
"k8s.io/kubernetes/pkg/api"
25-
"k8s.io/kubernetes/pkg/api/v1"
26-
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
2727
)
2828

2929
const (
@@ -118,7 +118,7 @@ func main() {
118118
if err != nil {
119119
glog.Fatalf("Failed to load kubeconfig: %v", err)
120120
}
121-
client := clientset.NewForConfigOrDie(kubeConfig)
121+
client := kubernetes.NewForConfigOrDie(kubeConfig)
122122

123123
load := func(rawData []byte, filepath string) []byte {
124124
if len(rawData) > 0 {
@@ -156,7 +156,7 @@ func main() {
156156
run(client, kubelet)
157157
}
158158

159-
func run(client clientset.Interface, kubelet *kubeletClient) {
159+
func run(client kubernetes.Interface, kubelet *kubeletClient) {
160160
for {
161161
time.Sleep(3 * time.Second)
162162

@@ -323,7 +323,7 @@ func process(localRunningPods, localParentPods, apiParentPods, activeCheckpoints
323323
// - sanitize their podSpec, removing unnecessary information
324324
// - store the manifest on disk in an "inactive" checkpoint location
325325
//TODO(aaron): Add support for checkpointing configMaps
326-
func createCheckpointsForValidParents(client clientset.Interface, pods map[string]*v1.Pod) {
326+
func createCheckpointsForValidParents(client kubernetes.Interface, pods map[string]*v1.Pod) {
327327
for _, pod := range pods {
328328
// This merely check that the last kubelet pod state thinks this pod was running. It's possible that
329329
// state is actually stale (only as recent as last successful contact with api-server). However, this
@@ -473,7 +473,7 @@ func getFileCheckpoints(path string) map[string]*v1.Pod {
473473
}
474474

475475
// getAPIParentPods will retrieve all pods from apiserver that are parents & should be checkpointed
476-
func getAPIParentPods(client clientset.Interface, nodeName string) map[string]*v1.Pod {
476+
func getAPIParentPods(client kubernetes.Interface, nodeName string) map[string]*v1.Pod {
477477
opts := metav1.ListOptions{
478478
FieldSelector: fields.OneTermEqualSelector(api.PodHostField, nodeName).String(),
479479
}
@@ -533,7 +533,7 @@ func (c *kubeletClient) localRunningPods() (map[string]*v1.Pod, error) {
533533
}
534534

535535
// checkpointSecretVolumes ensures that all pod secrets are checkpointed locally, then converts the secret volume to a hostpath.
536-
func checkpointSecretVolumes(client clientset.Interface, pod *v1.Pod) (*v1.Pod, error) {
536+
func checkpointSecretVolumes(client kubernetes.Interface, pod *v1.Pod) (*v1.Pod, error) {
537537
for i := range pod.Spec.Volumes {
538538
v := &pod.Spec.Volumes[i]
539539
if v.Secret == nil {
@@ -555,7 +555,7 @@ func checkpointSecretVolumes(client clientset.Interface, pod *v1.Pod) (*v1.Pod,
555555
// checkpointSecret will locally store secret data.
556556
// The path to the secret data becomes: checkpointSecretPath/namespace/podname/secretName/secret.file
557557
// Where each "secret.file" is a key from the secret.Data field.
558-
func checkpointSecret(client clientset.Interface, namespace, podName, secretName string) (string, error) {
558+
func checkpointSecret(client kubernetes.Interface, namespace, podName, secretName string) (string, error) {
559559
secret, err := client.Core().Secrets(namespace).Get(secretName, metav1.GetOptions{})
560560
if err != nil {
561561
return "", fmt.Errorf("failed to retrieve secret %s/%s: %v", namespace, secretName, err)
@@ -575,7 +575,7 @@ func checkpointSecret(client clientset.Interface, namespace, podName, secretName
575575
}
576576

577577
// checkpointConfigMapVolumes ensures that all pod configMaps are checkpointed locally, then converts the configMap volume to a hostpath.
578-
func checkpointConfigMapVolumes(client clientset.Interface, pod *v1.Pod) (*v1.Pod, error) {
578+
func checkpointConfigMapVolumes(client kubernetes.Interface, pod *v1.Pod) (*v1.Pod, error) {
579579
for i := range pod.Spec.Volumes {
580580
v := &pod.Spec.Volumes[i]
581581
if v.ConfigMap == nil {
@@ -596,7 +596,7 @@ func checkpointConfigMapVolumes(client clientset.Interface, pod *v1.Pod) (*v1.Po
596596
// checkpointConfigMap will locally store configMap data.
597597
// The path to the configMap data becomes: checkpointSecretPath/namespace/podname/configMapName/configMap.file
598598
// Where each "configMap.file" is a key from the configMap.Data field.
599-
func checkpointConfigMap(client clientset.Interface, namespace, podName, configMapName string) (string, error) {
599+
func checkpointConfigMap(client kubernetes.Interface, namespace, podName, configMapName string) (string, error) {
600600
configMap, err := client.Core().ConfigMaps(namespace).Get(configMapName, metav1.GetOptions{})
601601
if err != nil {
602602
return "", fmt.Errorf("failed to retrieve configMap %s/%s: %v", namespace, configMapName, err)

cmd/checkpoint/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"testing"
77

88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9-
"k8s.io/kubernetes/pkg/api"
10-
"k8s.io/kubernetes/pkg/api/v1"
9+
"k8s.io/client-go/pkg/api"
10+
"k8s.io/client-go/pkg/api/v1"
1111
)
1212

1313
func TestProcess(t *testing.T) {

0 commit comments

Comments
 (0)