Skip to content
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

Use volumeutil.LoadPodFromFile for pod spec #55380

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/phases/selfhosting/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_test(
deps = [
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor/k8s.io/api/apps/v1beta2:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
],
Expand All @@ -37,11 +38,10 @@ go_library(
"//cmd/kubeadm/app/features:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//cmd/kubeadm/app/util/apiclient:go_default_library",
"//pkg/api/legacyscheme:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor/k8s.io/api/apps/v1beta2:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
],
)
Expand Down
25 changes: 4 additions & 21 deletions cmd/kubeadm/app/phases/selfhosting/selfhosting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ package selfhosting

import (
"fmt"
"io/ioutil"
"os"
"time"

apps "k8s.io/api/apps/v1beta2"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kuberuntime "k8s.io/apimachinery/pkg/runtime"
clientset "k8s.io/client-go/kubernetes"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/features"
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
"k8s.io/kubernetes/pkg/api/legacyscheme"
volumeutil "k8s.io/kubernetes/pkg/volume/util"
)

const (
Expand Down Expand Up @@ -59,7 +57,7 @@ func CreateSelfHostedControlPlane(manifestsDir, kubeConfigDir string, cfg *kubea
// Adjust the timeout slightly to something self-hosting specific
waiter.SetTimeout(selfHostingWaitTimeout)

// Here the map of different mutators to use for the control plane's podspec is stored
// Here the map of different mutators to use for the control plane's PodSpec is stored
mutators := GetMutatorsFromFeatureGates(cfg.FeatureGates)

// Some extra work to be done if we should store the control plane certificates in Secrets
Expand All @@ -85,10 +83,11 @@ func CreateSelfHostedControlPlane(manifestsDir, kubeConfigDir string, cfg *kubea
}

// Load the Static Pod file in order to be able to create a self-hosted variant of that file
podSpec, err := loadPodSpecFromFile(manifestPath)
pod, err := volumeutil.LoadPodFromFile(manifestPath)
if err != nil {
return err
}
podSpec := &pod.Spec

// Build a DaemonSet object from the loaded PodSpec
ds := BuildDaemonSet(componentName, podSpec, mutators)
Expand Down Expand Up @@ -156,22 +155,6 @@ func BuildDaemonSet(name string, podSpec *v1.PodSpec, mutators map[string][]PodS
}
}

// loadPodSpecFromFile reads and decodes a file containing a specification of a Pod
// TODO: Consider using "k8s.io/kubernetes/pkg/volume/util".LoadPodFromFile(filename string) in the future instead.
func loadPodSpecFromFile(manifestPath string) (*v1.PodSpec, error) {
podBytes, err := ioutil.ReadFile(manifestPath)
if err != nil {
return nil, err
}

staticPod := &v1.Pod{}
if err := kuberuntime.DecodeInto(legacyscheme.Codecs.UniversalDecoder(), podBytes, staticPod); err != nil {
return nil, fmt.Errorf("unable to decode static pod %v", err)
}

return &staticPod.Spec, nil
}

// BuildSelfhostedComponentLabels returns the labels for a self-hosted component
func BuildSelfhostedComponentLabels(component string) map[string]string {
return map[string]string{
Expand Down
6 changes: 4 additions & 2 deletions cmd/kubeadm/app/phases/selfhosting/selfhosting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apps "k8s.io/api/apps/v1beta2"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/util"
volumeutil "k8s.io/kubernetes/pkg/volume/util"
)

const (
Expand Down Expand Up @@ -479,10 +480,11 @@ func TestBuildDaemonSet(t *testing.T) {
}
defer os.Remove(tempFile)

podSpec, err := loadPodSpecFromFile(tempFile)
pod, err := volumeutil.LoadPodFromFile(tempFile)
if err != nil {
t.Fatalf("couldn't load the specified Pod")
}
podSpec := &pod.Spec

ds := BuildDaemonSet(rt.component, podSpec, GetDefaultMutators())
dsBytes, err := util.MarshalToYaml(ds, apps.SchemeGroupVersion)
Expand Down Expand Up @@ -554,7 +556,7 @@ spec:
}
defer os.Remove(tempFile)

_, err = loadPodSpecFromFile(tempFile)
_, err = volumeutil.LoadPodFromFile(tempFile)
if (err != nil) != rt.expectError {
t.Errorf("failed TestLoadPodSpecFromFile:\nexpected error:\n%t\nsaw:\n%v", rt.expectError, err)
}
Expand Down