diff --git a/nodeup/pkg/model/context.go b/nodeup/pkg/model/context.go index 72490a4869..709b25a2a8 100644 --- a/nodeup/pkg/model/context.go +++ b/nodeup/pkg/model/context.go @@ -66,9 +66,7 @@ func (c *NodeupModelContext) Init() error { } c.kubernetesVersion = *k8sVersion - if c.InstanceGroup == nil { - klog.Warningf("cannot determine role, InstanceGroup not set") - } else if c.InstanceGroup.Spec.Role == kops.InstanceGroupRoleMaster { + if c.NodeupConfig.InstanceGroupRole == kops.InstanceGroupRoleMaster { c.IsMaster = true } diff --git a/nodeup/pkg/model/file_assets.go b/nodeup/pkg/model/file_assets.go index d0e81cb6aa..05818de32d 100644 --- a/nodeup/pkg/model/file_assets.go +++ b/nodeup/pkg/model/file_assets.go @@ -64,7 +64,7 @@ func (f *FileAssetsBuilder) Build(c *fi.ModelBuilderContext) error { func (f *FileAssetsBuilder) buildFileAssets(c *fi.ModelBuilderContext, assets []kops.FileAssetSpec, tracker map[string]bool) error { for _, asset := range assets { // @check if the file asset applies to us. If no roles applied we assume its applied to all roles - if len(asset.Roles) > 0 && !containsRole(f.InstanceGroup.Spec.Role, asset.Roles) { + if len(asset.Roles) > 0 && !containsRole(f.NodeupConfig.InstanceGroupRole, asset.Roles) { continue } // @check if e have a path and if not use the default path diff --git a/nodeup/pkg/model/hooks.go b/nodeup/pkg/model/hooks.go index ee503a5241..7a3f766e9e 100644 --- a/nodeup/pkg/model/hooks.go +++ b/nodeup/pkg/model/hooks.go @@ -44,7 +44,7 @@ func (h *HookBuilder) Build(c *fi.ModelBuilderContext) error { for j, hook := range *spec { isInstanceGroup := i == 0 // filter roles if required - if len(hook.Roles) > 0 && !containsRole(h.InstanceGroup.Spec.Role, hook.Roles) { + if len(hook.Roles) > 0 && !containsRole(h.NodeupConfig.InstanceGroupRole, hook.Roles) { continue } diff --git a/nodeup/pkg/model/kubelet_test.go b/nodeup/pkg/model/kubelet_test.go index 4b4eb2c5af..8b384bf828 100644 --- a/nodeup/pkg/model/kubelet_test.go +++ b/nodeup/pkg/model/kubelet_test.go @@ -24,6 +24,7 @@ import ( "k8s.io/klog" "k8s.io/kops/nodeup/pkg/distros" "k8s.io/kops/pkg/apis/kops" + "k8s.io/kops/pkg/apis/nodeup" "k8s.io/kops/pkg/assets" "k8s.io/kops/pkg/client/simple/vfsclientset" "k8s.io/kops/pkg/pki" @@ -48,6 +49,7 @@ func Test_InstanceGroupKubeletMerge(t *testing.T) { &NodeupModelContext{ Cluster: cluster, InstanceGroup: instanceGroup, + NodeupConfig: nodeup.NewConfig(cluster, instanceGroup), }, } if err := b.Init(); err != nil { @@ -91,6 +93,7 @@ func TestTaintsApplied(t *testing.T) { &NodeupModelContext{ Cluster: cluster, InstanceGroup: ig, + NodeupConfig: nodeup.NewConfig(cluster, ig), }, } if err := b.Init(); err != nil { @@ -205,12 +208,14 @@ func BuildNodeupModelContext(basedir string) (*NodeupModelContext, error) { Cluster: model.Cluster, Architecture: "amd64", Distribution: distros.DistributionXenial, + NodeupConfig: &nodeup.Config{}, } if len(model.InstanceGroups) == 0 { // We tolerate this - not all tests need an instance group } else if len(model.InstanceGroups) == 1 { nodeUpModelContext.InstanceGroup = model.InstanceGroups[0] + nodeUpModelContext.NodeupConfig = nodeup.NewConfig(model.Cluster, nodeUpModelContext.InstanceGroup) } else { return nil, fmt.Errorf("unexpected number of instance groups in %s, found %d", basedir, len(model.InstanceGroups)) } diff --git a/pkg/apis/nodeup/BUILD.bazel b/pkg/apis/nodeup/BUILD.bazel index 130e98c72d..03f16aea5d 100644 --- a/pkg/apis/nodeup/BUILD.bazel +++ b/pkg/apis/nodeup/BUILD.bazel @@ -5,4 +5,5 @@ go_library( srcs = ["config.go"], importpath = "k8s.io/kops/pkg/apis/nodeup", visibility = ["//visibility:public"], + deps = ["//pkg/apis/kops:go_default_library"], ) diff --git a/pkg/apis/nodeup/config.go b/pkg/apis/nodeup/config.go index deefb7f8b3..d677c9489a 100644 --- a/pkg/apis/nodeup/config.go +++ b/pkg/apis/nodeup/config.go @@ -16,6 +16,8 @@ limitations under the License. package nodeup +import "k8s.io/kops/pkg/apis/kops" + // Config is the configuration for the nodeup binary type Config struct { // Tags enable/disable chunks of the model @@ -31,6 +33,8 @@ type Config struct { ClusterLocation *string `json:",omitempty"` // InstanceGroupName is the name of the instance group InstanceGroupName string `json:",omitempty"` + // InstanceGroupRole is the instance group role. + InstanceGroupRole kops.InstanceGroupRole // ClusterName is the name of the cluster ClusterName string `json:",omitempty"` // ProtokubeImage is the docker image to load for protokube (bootstrapping) @@ -63,3 +67,9 @@ type StaticManifest struct { // Path is the path to the manifest Path string `json:"path,omitempty"` } + +func NewConfig(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) *Config { + return &Config{ + InstanceGroupRole: instanceGroup.Spec.Role, + } +} diff --git a/pkg/model/bootstrapscript_test.go b/pkg/model/bootstrapscript_test.go index cdced004f9..bb1f84139f 100644 --- a/pkg/model/bootstrapscript_test.go +++ b/pkg/model/bootstrapscript_test.go @@ -114,7 +114,7 @@ func TestBootstrapUserData(t *testing.T) { group := makeTestInstanceGroup(x.Role, x.HookSpecRoles, x.FileAssetSpecRoles) renderNodeUpConfig := func(ig *kops.InstanceGroup) (*nodeup.Config, error) { - return &nodeup.Config{}, nil + return nodeup.NewConfig(cluster, ig), nil } bs := &BootstrapScript{ diff --git a/upup/pkg/fi/cloudup/apply_cluster.go b/upup/pkg/fi/cloudup/apply_cluster.go index 1b080964fd..0a39ec81c1 100644 --- a/upup/pkg/fi/cloudup/apply_cluster.go +++ b/upup/pkg/fi/cloudup/apply_cluster.go @@ -1254,7 +1254,7 @@ func (c *ApplyClusterCmd) BuildNodeUpConfig(assetBuilder *assets.AssetBuilder, i return nil, err } - config := &nodeup.Config{} + config := nodeup.NewConfig(cluster, ig) config.Tags = append(config.Tags, nodeUpTags.List()...) for _, a := range c.Assets {