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

Start moving InstanceGroup data to NodeupConfig #9391

Merged
merged 4 commits into from
Jun 18, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions nodeup/pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -308,11 +306,7 @@ func (c *NodeupModelContext) UseEtcdTLS() bool {
// UseVolumeMounts is used to check if we have volume mounts enabled as we need to
// insert requires and afters in various places
func (c *NodeupModelContext) UseVolumeMounts() bool {
if c.InstanceGroup != nil {
return len(c.InstanceGroup.Spec.VolumeMounts) > 0
}

return false
return len(c.NodeupConfig.VolumeMounts) > 0
}

// UseEtcdTLSAuth checks the peer-auth is set in both cluster
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/file_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions nodeup/pkg/model/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/sysctls.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (b *SysctlBuilder) Build(c *fi.ModelBuilderContext) error {
"net.ipv4.ip_forward=1",
"")

if params := b.InstanceGroup.Spec.SysctlParameters; len(params) > 0 {
if params := b.NodeupConfig.SysctlParameters; len(params) > 0 {
sysctls = append(sysctls,
"# Custom sysctl parameters from instance group spec",
"")
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *VolumesBuilder) Build(c *fi.ModelBuilderContext) error {
}

// @step: iterate the volume mounts and attempt to mount the devices
for _, x := range b.InstanceGroup.Spec.VolumeMounts {
for _, x := range b.NodeupConfig.VolumeMounts {
// @check the directory exists, else create it
if err := b.EnsureDirectory(x.Path); err != nil {
return fmt.Errorf("failed to ensure the directory: %s, error: %s", x.Path, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/nodeup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
18 changes: 18 additions & 0 deletions pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -44,6 +48,12 @@ type Config struct {
// StaticManifests describes generic static manifests
// Using this allows us to keep complex logic out of nodeup
StaticManifests []*StaticManifest `json:"staticManifests,omitempty"`
// SysctlParameters will configure kernel parameters using sysctl(8). When
// specified, each parameter must follow the form variable=value, the way
// it would appear in sysctl.conf.
SysctlParameters []string `json:",omitempty"`
// VolumeMounts are a collection of volume mounts.
VolumeMounts []*kops.VolumeMountSpec `json:",omitempty"`
}

// Image is a docker image we should pre-load
Expand All @@ -63,3 +73,11 @@ 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,
SysctlParameters: instanceGroup.Spec.SysctlParameters,
VolumeMounts: instanceGroup.Spec.VolumeMounts,
}
}
2 changes: 1 addition & 1 deletion pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/tests/data/bootstrapscript_0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ taints:
__EOF_IG_SPEC

cat > conf/kube_env.yaml << '__EOF_KUBE_ENV'
{}
InstanceGroupRole: Master

__EOF_KUBE_ENV

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/tests/data/bootstrapscript_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ taints:
__EOF_IG_SPEC

cat > conf/kube_env.yaml << '__EOF_KUBE_ENV'
{}
InstanceGroupRole: Master

__EOF_KUBE_ENV

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/tests/data/bootstrapscript_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ taints:
__EOF_IG_SPEC

cat > conf/kube_env.yaml << '__EOF_KUBE_ENV'
{}
InstanceGroupRole: Master

__EOF_KUBE_ENV

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/tests/data/bootstrapscript_3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ taints:
__EOF_IG_SPEC

cat > conf/kube_env.yaml << '__EOF_KUBE_ENV'
{}
InstanceGroupRole: Node

__EOF_KUBE_ENV

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/tests/data/bootstrapscript_4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ taints:
__EOF_IG_SPEC

cat > conf/kube_env.yaml << '__EOF_KUBE_ENV'
{}
InstanceGroupRole: Node

__EOF_KUBE_ENV

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/tests/data/bootstrapscript_5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ taints:
__EOF_IG_SPEC

cat > conf/kube_env.yaml << '__EOF_KUBE_ENV'
{}
InstanceGroupRole: Node

__EOF_KUBE_ENV

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Resources.AWSEC2LaunchTemplatemasterustest1bmastersadditionalcidrexamplecom.Prop
ClusterName: additionalcidr.example.com
ConfigBase: memfs://clusters.example.com/additionalcidr.example.com
InstanceGroupName: master-us-test-1b
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down Expand Up @@ -501,6 +502,7 @@ Resources.AWSEC2LaunchTemplatenodesadditionalcidrexamplecom.Properties.LaunchTem
ClusterName: additionalcidr.example.com
ConfigBase: memfs://clusters.example.com/additionalcidr.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Assets:
ClusterName: additionalcidr.example.com
ConfigBase: memfs://clusters.example.com/additionalcidr.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Assets:
ClusterName: additionalcidr.example.com
ConfigBase: memfs://clusters.example.com/additionalcidr.example.com
InstanceGroupName: master-us-test-1b
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Assets:
ClusterName: additionalcidr.example.com
ConfigBase: memfs://clusters.example.com/additionalcidr.example.com
InstanceGroupName: master-us-test-1c
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Assets:
ClusterName: additionalcidr.example.com
ConfigBase: memfs://clusters.example.com/additionalcidr.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ Resources.AWSEC2LaunchTemplatemasterustest1amastersadditionaluserdataexamplecom.
ClusterName: additionaluserdata.example.com
ConfigBase: memfs://clusters.example.com/additionaluserdata.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down Expand Up @@ -530,6 +531,7 @@ Resources.AWSEC2LaunchTemplatenodesadditionaluserdataexamplecom.Properties.Launc
ClusterName: additionaluserdata.example.com
ConfigBase: memfs://clusters.example.com/additionaluserdata.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Assets:
ClusterName: crosszone.example.com
ConfigBase: memfs://clusters.example.com/crosszone.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Assets:
ClusterName: crosszone.example.com
ConfigBase: memfs://clusters.example.com/crosszone.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ Assets:
ClusterName: bastionuserdata.example.com
ConfigBase: memfs://clusters.example.com/bastionuserdata.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Assets:
ClusterName: bastionuserdata.example.com
ConfigBase: memfs://clusters.example.com/bastionuserdata.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Resources.AWSEC2LaunchTemplatemasterustest1amasterscomplexexamplecom.Properties.
ClusterName: complex.example.com
ConfigBase: memfs://clusters.example.com/complex.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down Expand Up @@ -503,6 +504,7 @@ Resources.AWSEC2LaunchTemplatenodescomplexexamplecom.Properties.LaunchTemplateDa
ClusterName: complex.example.com
ConfigBase: memfs://clusters.example.com/complex.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Assets:
ClusterName: complex.example.com
ConfigBase: memfs://clusters.example.com/complex.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Assets:
ClusterName: complex.example.com
ConfigBase: memfs://clusters.example.com/complex.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Resources.AWSEC2LaunchTemplatemasterustest1amasterscontainerdexamplecom.Properti
ClusterName: containerd.example.com
ConfigBase: memfs://clusters.example.com/containerd.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down Expand Up @@ -499,6 +500,7 @@ Resources.AWSEC2LaunchTemplatenodescontainerdexamplecom.Properties.LaunchTemplat
ClusterName: containerd.example.com
ConfigBase: memfs://clusters.example.com/containerd.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Assets:
ClusterName: existing-iam.example.com
ConfigBase: memfs://tests/existing-iam.example.com
InstanceGroupName: master-us-test-1a
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Assets:
ClusterName: existing-iam.example.com
ConfigBase: memfs://tests/existing-iam.example.com
InstanceGroupName: master-us-test-1b
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Assets:
ClusterName: existing-iam.example.com
ConfigBase: memfs://tests/existing-iam.example.com
InstanceGroupName: master-us-test-1c
InstanceGroupRole: Master
Tags:
- _automatic_upgrades
- _aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Assets:
ClusterName: existing-iam.example.com
ConfigBase: memfs://tests/existing-iam.example.com
InstanceGroupName: nodes
InstanceGroupRole: Node
Tags:
- _automatic_upgrades
- _aws
Expand Down
Loading