mirror of https://github.com/kubernetes/kops.git
Merge pull request #14397 from justinsb/nodeconfig_typing
nodeup script: accept strongly typed nodeup.Config
This commit is contained in:
commit
0b01e26d44
|
|
@ -78,13 +78,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// kubeEnv returns the boot config for the instance group
|
// kubeEnv returns the boot config for the instance group
|
||||||
func (b *BootstrapScript) kubeEnv(ig *kops.InstanceGroup, c *fi.Context) (string, error) {
|
func (b *BootstrapScript) kubeEnv(ig *kops.InstanceGroup, c *fi.Context) (*nodeup.BootConfig, error) {
|
||||||
var alternateNames []string
|
var alternateNames []string
|
||||||
|
|
||||||
for _, hasAddress := range b.alternateNameTasks {
|
for _, hasAddress := range b.alternateNameTasks {
|
||||||
addresses, err := hasAddress.FindAddresses(c)
|
addresses, err := hasAddress.FindAddresses(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error finding address for %v: %v", hasAddress, err)
|
return nil, fmt.Errorf("error finding address for %v: %v", hasAddress, err)
|
||||||
}
|
}
|
||||||
if len(addresses) == 0 {
|
if len(addresses) == 0 {
|
||||||
// Such tasks won't have an address in dry-run mode, until the resource is created
|
// Such tasks won't have an address in dry-run mode, until the resource is created
|
||||||
|
|
@ -104,29 +104,24 @@ func (b *BootstrapScript) kubeEnv(ig *kops.InstanceGroup, c *fi.Context) (string
|
||||||
name := *caTask.Name
|
name := *caTask.Name
|
||||||
keyset := caTask.Keyset()
|
keyset := caTask.Keyset()
|
||||||
if keyset == nil {
|
if keyset == nil {
|
||||||
return "", fmt.Errorf("failed to get keyset from %q", name)
|
return nil, fmt.Errorf("failed to get keyset from %q", name)
|
||||||
}
|
}
|
||||||
keysets[name] = keyset
|
keysets[name] = keyset
|
||||||
}
|
}
|
||||||
config, bootConfig, err := b.builder.NodeUpConfigBuilder.BuildConfig(ig, alternateNames, keysets)
|
config, bootConfig, err := b.builder.NodeUpConfigBuilder.BuildConfig(ig, alternateNames, keysets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
configData, err := utils.YamlMarshal(config)
|
configData, err := utils.YamlMarshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error converting nodeup config to yaml: %v", err)
|
return nil, fmt.Errorf("error converting nodeup config to yaml: %v", err)
|
||||||
}
|
}
|
||||||
sum256 := sha256.Sum256(configData)
|
sum256 := sha256.Sum256(configData)
|
||||||
bootConfig.NodeupConfigHash = base64.StdEncoding.EncodeToString(sum256[:])
|
bootConfig.NodeupConfigHash = base64.StdEncoding.EncodeToString(sum256[:])
|
||||||
b.nodeupConfig.Resource = fi.NewBytesResource(configData)
|
b.nodeupConfig.Resource = fi.NewBytesResource(configData)
|
||||||
|
|
||||||
bootConfigData, err := utils.YamlMarshal(bootConfig)
|
return bootConfig, nil
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error converting boot config to yaml: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(bootConfigData), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BootstrapScript) buildEnvironmentVariables(cluster *kops.Cluster) (map[string]string, error) {
|
func (b *BootstrapScript) buildEnvironmentVariables(cluster *kops.Cluster) (map[string]string, error) {
|
||||||
|
|
@ -338,14 +333,14 @@ func (b *BootstrapScript) Run(c *fi.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := b.kubeEnv(b.ig, c)
|
bootConfig, err := b.kubeEnv(b.ig, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodeupScript resources.NodeUpScript
|
var nodeupScript resources.NodeUpScript
|
||||||
nodeupScript.NodeUpAssets = b.builder.NodeUpAssets
|
nodeupScript.NodeUpAssets = b.builder.NodeUpAssets
|
||||||
nodeupScript.KubeEnv = config
|
nodeupScript.BootConfig = bootConfig
|
||||||
|
|
||||||
{
|
{
|
||||||
nodeupScript.EnvironmentVariables = func() (string, error) {
|
nodeupScript.EnvironmentVariables = func() (string, error) {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,9 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/pkg/apis/nodeup"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/utils"
|
||||||
"k8s.io/kops/util/pkg/architectures"
|
"k8s.io/kops/util/pkg/architectures"
|
||||||
"k8s.io/kops/util/pkg/mirrors"
|
"k8s.io/kops/util/pkg/mirrors"
|
||||||
)
|
)
|
||||||
|
|
@ -181,7 +183,7 @@ echo "== nodeup node config done =="
|
||||||
// NodeUpScript is responsible for creating the nodeup script
|
// NodeUpScript is responsible for creating the nodeup script
|
||||||
type NodeUpScript struct {
|
type NodeUpScript struct {
|
||||||
NodeUpAssets map[architectures.Architecture]*mirrors.MirroredAsset
|
NodeUpAssets map[architectures.Architecture]*mirrors.MirroredAsset
|
||||||
KubeEnv string
|
BootConfig *nodeup.BootConfig
|
||||||
CompressUserData bool
|
CompressUserData bool
|
||||||
SetSysctls string
|
SetSysctls string
|
||||||
CloudProvider string
|
CloudProvider string
|
||||||
|
|
@ -231,8 +233,13 @@ func (b *NodeUpScript) Build() (fi.Resource, error) {
|
||||||
return ""
|
return ""
|
||||||
},
|
},
|
||||||
|
|
||||||
"KubeEnv": func() string {
|
"KubeEnv": func() (string, error) {
|
||||||
return b.KubeEnv
|
bootConfigData, err := utils.YamlMarshal(b.BootConfig)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error converting boot config to yaml: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bootConfigData), nil
|
||||||
},
|
},
|
||||||
|
|
||||||
"GzipBase64": func(data string) (string, error) {
|
"GzipBase64": func(data string) (string, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue