mirror of https://github.com/kubernetes/kops.git
Merge pull request #5351 from gambol99/remove_unrequired
Removing Duplication
This commit is contained in:
commit
cd820a6be9
|
|
@ -18,16 +18,15 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// s is a helper that builds a *string from a string value
|
// s is a helper that builds a *string from a string value
|
||||||
|
|
@ -93,68 +92,6 @@ func getProxyEnvVars(proxies *kops.EgressProxySpec) []v1.EnvVar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildCertificateRequest retrieves the certificate from a keystore
|
|
||||||
func buildCertificateRequest(c *fi.ModelBuilderContext, b *NodeupModelContext, name, path string) error {
|
|
||||||
cert, err := b.KeyStore.FindCert(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if cert == nil {
|
|
||||||
return fmt.Errorf("certificate %q not found", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized, err := cert.AsString()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
location := filepath.Join(b.PathSrvKubernetes(), fmt.Sprintf("%s.pem", name))
|
|
||||||
if path != "" {
|
|
||||||
location = path
|
|
||||||
}
|
|
||||||
|
|
||||||
c.AddTask(&nodetasks.File{
|
|
||||||
Path: location,
|
|
||||||
Contents: fi.NewStringResource(serialized),
|
|
||||||
Type: nodetasks.FileType_File,
|
|
||||||
Mode: s("0600"),
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildPrivateKeyRequest retrieves a private key from the store
|
|
||||||
func buildPrivateKeyRequest(c *fi.ModelBuilderContext, b *NodeupModelContext, name, path string) error {
|
|
||||||
k, err := b.KeyStore.FindPrivateKey(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if k == nil {
|
|
||||||
return fmt.Errorf("private key %q not found", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized, err := k.AsString()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
location := filepath.Join(b.PathSrvKubernetes(), fmt.Sprintf("%s-key.pem", name))
|
|
||||||
if path != "" {
|
|
||||||
location = path
|
|
||||||
}
|
|
||||||
|
|
||||||
c.AddTask(&nodetasks.File{
|
|
||||||
Path: location,
|
|
||||||
Contents: fi.NewStringResource(serialized),
|
|
||||||
Type: nodetasks.FileType_File,
|
|
||||||
Mode: s("0600"),
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// sortedStrings is just a one liner helper methods
|
// sortedStrings is just a one liner helper methods
|
||||||
func sortedStrings(list []string) []string {
|
func sortedStrings(list []string) []string {
|
||||||
sort.Strings(list)
|
sort.Strings(list)
|
||||||
|
|
|
||||||
|
|
@ -94,10 +94,10 @@ func (b *KubeAPIServerBuilder) Build(c *fi.ModelBuilderContext) error {
|
||||||
// @check if we are using secure client certificates for kubelet and grab the certificates
|
// @check if we are using secure client certificates for kubelet and grab the certificates
|
||||||
if b.UseSecureKubelet() {
|
if b.UseSecureKubelet() {
|
||||||
name := "kubelet-api"
|
name := "kubelet-api"
|
||||||
if err := buildCertificateRequest(c, b.NodeupModelContext, name, ""); err != nil {
|
if err := b.BuildCertificateTask(c, name, name+".pem"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := buildPrivateKeyRequest(c, b.NodeupModelContext, name, ""); err != nil {
|
if err := b.BuildPrivateKeyTask(c, name, name+"-key.pem"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue