Add generated file
This PR adds generated files under pkg/client and vendor folder.
This commit is contained in:
41
vendor/k8s.io/kubernetes/pkg/kubelet/checkpoint/BUILD
generated
vendored
Normal file
41
vendor/k8s.io/kubernetes/pkg/kubelet/checkpoint/BUILD
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["checkpoint.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/checkpoint",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/kubelet/checkpointmanager:go_default_library",
|
||||
"//pkg/kubelet/checkpointmanager/checksum:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["checkpoint_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/kubelet/checkpointmanager:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
128
vendor/k8s.io/kubernetes/pkg/kubelet/checkpoint/checkpoint.go
generated
vendored
Normal file
128
vendor/k8s.io/kubernetes/pkg/kubelet/checkpoint/checkpoint.go
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Copyright 2017 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 checkpoint
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
|
||||
)
|
||||
|
||||
const (
|
||||
// Delimiter used on checkpoints written to disk
|
||||
delimiter = "_"
|
||||
podPrefix = "Pod"
|
||||
)
|
||||
|
||||
type PodCheckpoint interface {
|
||||
checkpointmanager.Checkpoint
|
||||
GetPod() *v1.Pod
|
||||
}
|
||||
|
||||
// Data to be stored as checkpoint
|
||||
type Data struct {
|
||||
Pod *v1.Pod
|
||||
Checksum checksum.Checksum
|
||||
}
|
||||
|
||||
// NewPodCheckpoint returns new pod checkpoint
|
||||
func NewPodCheckpoint(pod *v1.Pod) PodCheckpoint {
|
||||
return &Data{Pod: pod}
|
||||
}
|
||||
|
||||
// MarshalCheckpoint returns marshalled data
|
||||
func (cp *Data) MarshalCheckpoint() ([]byte, error) {
|
||||
cp.Checksum = checksum.New(*cp.Pod)
|
||||
return json.Marshal(*cp)
|
||||
}
|
||||
|
||||
// UnmarshalCheckpoint returns unmarshalled data
|
||||
func (cp *Data) UnmarshalCheckpoint(blob []byte) error {
|
||||
return json.Unmarshal(blob, cp)
|
||||
}
|
||||
|
||||
// VerifyChecksum verifies that passed checksum is same as calculated checksum
|
||||
func (cp *Data) VerifyChecksum() error {
|
||||
return cp.Checksum.Verify(*cp.Pod)
|
||||
}
|
||||
|
||||
func (cp *Data) GetPod() *v1.Pod {
|
||||
return cp.Pod
|
||||
}
|
||||
|
||||
// checkAnnotations will validate the checkpoint annotations exist on the Pod
|
||||
func checkAnnotations(pod *v1.Pod) bool {
|
||||
if podAnnotations := pod.GetAnnotations(); podAnnotations != nil {
|
||||
if podAnnotations[core.BootstrapCheckpointAnnotationKey] == "true" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//getPodKey returns the full qualified path for the pod checkpoint
|
||||
func getPodKey(pod *v1.Pod) string {
|
||||
return fmt.Sprintf("Pod%v%v.yaml", delimiter, pod.GetUID())
|
||||
}
|
||||
|
||||
// LoadPods Loads All Checkpoints from disk
|
||||
func LoadPods(cpm checkpointmanager.CheckpointManager) ([]*v1.Pod, error) {
|
||||
pods := make([]*v1.Pod, 0)
|
||||
|
||||
var err error
|
||||
checkpointKeys := []string{}
|
||||
checkpointKeys, err = cpm.ListCheckpoints()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to list checkpoints: %v", err)
|
||||
}
|
||||
|
||||
for _, key := range checkpointKeys {
|
||||
checkpoint := NewPodCheckpoint(nil)
|
||||
err := cpm.GetCheckpoint(key, checkpoint)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve checkpoint for pod %q: %v", key, err)
|
||||
continue
|
||||
}
|
||||
pods = append(pods, checkpoint.GetPod())
|
||||
}
|
||||
return pods, nil
|
||||
}
|
||||
|
||||
// WritePod a checkpoint to a file on disk if annotation is present
|
||||
func WritePod(cpm checkpointmanager.CheckpointManager, pod *v1.Pod) error {
|
||||
var err error
|
||||
if checkAnnotations(pod) {
|
||||
data := NewPodCheckpoint(pod)
|
||||
err = cpm.CreateCheckpoint(getPodKey(pod), data)
|
||||
} else {
|
||||
// This is to handle an edge where a pod update could remove
|
||||
// an annotation and the checkpoint should then be removed.
|
||||
err = cpm.RemoveCheckpoint(getPodKey(pod))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// DeletePod deletes a checkpoint from disk if present
|
||||
func DeletePod(cpm checkpointmanager.CheckpointManager, pod *v1.Pod) error {
|
||||
return cpm.RemoveCheckpoint(getPodKey(pod))
|
||||
}
|
124
vendor/k8s.io/kubernetes/pkg/kubelet/checkpoint/checkpoint_test.go
generated
vendored
Normal file
124
vendor/k8s.io/kubernetes/pkg/kubelet/checkpoint/checkpoint_test.go
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright 2017 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 checkpoint
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||
)
|
||||
|
||||
// TestWriteLoadDeletePods validates all combinations of write, load, and delete
|
||||
func TestWriteLoadDeletePods(t *testing.T) {
|
||||
testPods := []struct {
|
||||
pod *v1.Pod
|
||||
written bool
|
||||
}{
|
||||
{
|
||||
pod: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "Foo",
|
||||
Annotations: map[string]string{core.BootstrapCheckpointAnnotationKey: "true"},
|
||||
UID: "1",
|
||||
},
|
||||
},
|
||||
written: true,
|
||||
},
|
||||
{
|
||||
pod: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "Foo2",
|
||||
Annotations: map[string]string{core.BootstrapCheckpointAnnotationKey: "true"},
|
||||
UID: "2",
|
||||
},
|
||||
},
|
||||
written: true,
|
||||
},
|
||||
{
|
||||
pod: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "Bar",
|
||||
UID: "3",
|
||||
},
|
||||
},
|
||||
written: false,
|
||||
},
|
||||
}
|
||||
|
||||
dir, err := ioutil.TempDir("", "checkpoint")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to allocate temp directory for TestWriteLoadDeletePods error=%v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
cpm, err := checkpointmanager.NewCheckpointManager(dir)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to initialize checkpoint manager error=%v", err)
|
||||
}
|
||||
for _, p := range testPods {
|
||||
// Write pods should always pass unless there is an fs error
|
||||
if err := WritePod(cpm, p.pod); err != nil {
|
||||
t.Errorf("Failed to Write Pod: %v", err)
|
||||
}
|
||||
}
|
||||
// verify the correct written files are loaded from disk
|
||||
pods, err := LoadPods(cpm)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to Load Pods: %v", err)
|
||||
}
|
||||
// loop through contents and check make sure
|
||||
// what was loaded matched the expected results.
|
||||
for _, p := range testPods {
|
||||
pname := p.pod.GetName()
|
||||
var lpod *v1.Pod
|
||||
for _, check := range pods {
|
||||
if check.GetName() == pname {
|
||||
lpod = check
|
||||
break
|
||||
}
|
||||
}
|
||||
if p.written {
|
||||
if lpod != nil {
|
||||
if !reflect.DeepEqual(p.pod, lpod) {
|
||||
t.Errorf("expected %#v, \ngot %#v", p.pod, lpod)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("Got unexpected result for %v, should have been loaded", pname)
|
||||
}
|
||||
} else if lpod != nil {
|
||||
t.Errorf("Got unexpected result for %v, should not have been loaded", pname)
|
||||
}
|
||||
err = DeletePod(cpm, p.pod)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to delete pod %v", pname)
|
||||
}
|
||||
}
|
||||
// finally validate the contents of the directory is empty.
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to read directory %v", dir)
|
||||
}
|
||||
if len(files) > 0 {
|
||||
t.Errorf("Directory %v should be empty but found %#v", dir, files)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user