Skip to content

Commit

Permalink
Remove references to control-plane-specific ClusterSpec fields from n…
Browse files Browse the repository at this point in the history
…odeup
  • Loading branch information
johngmyers committed Jul 28, 2023
1 parent 683761a commit e317648
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
12 changes: 0 additions & 12 deletions nodeup/pkg/model/containerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,8 @@ func runContainerdBuilderTest(t *testing.T, key string, distro distributions.Dis
}

func TestContainerdConfig(t *testing.T) {
cluster := &kops.Cluster{
Spec: kops.ClusterSpec{
ContainerRuntime: "containerd",
Containerd: &kops.ContainerdConfig{},
KubernetesVersion: "1.21.0",
Networking: kops.NetworkingSpec{
Kubenet: &kops.KubenetNetworkingSpec{},
},
},
}

b := &ContainerdBuilder{
NodeupModelContext: &NodeupModelContext{
Cluster: cluster,
NodeupConfig: &nodeup.Config{
ContainerRuntime: "containerd",
ContainerdConfig: &kops.ContainerdConfig{},
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/kube_controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (b *KubeControllerManagerBuilder) Build(c *fi.NodeupModelBuilderContext) er

pathSrvKCM := filepath.Join(b.PathSrvKubernetes(), "kube-controller-manager")

kcm := *b.Cluster.Spec.KubeControllerManager
kcm := b.NodeupConfig.ControlPlaneConfig.KubeControllerManager
kcm.RootCAFile = filepath.Join(b.PathSrvKubernetes(), "ca.crt")

// Include the CA Key
Expand Down
16 changes: 7 additions & 9 deletions nodeup/pkg/model/kube_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@ func TestKubeProxyBuilder_buildPod(t *testing.T) {
// https://pkg.go.dev/k8s.io/kops/pkg/apis/kops#ClusterSpec
// https://pkg.go.dev/k8s.io/kops/pkg/apis/kops#KubeProxyConfig

cluster := &kops.Cluster{}

cluster.Spec.KubeProxy = &kops.KubeProxyConfig{}
cluster.Spec.KubeProxy.Image = "kube-proxy:1.2"
cluster.Spec.KubeProxy.CPURequest = resource.NewScaledQuantity(20, resource.Milli)
cluster.Spec.KubeProxy.CPULimit = resource.NewScaledQuantity(30, resource.Milli)
kubeProxy := kops.KubeProxyConfig{
Image: "kube-proxy:1.2",
CPURequest: resource.NewScaledQuantity(20, resource.Milli),
CPULimit: resource.NewScaledQuantity(30, resource.Milli),
}

nodeupConfig := &nodeup.Config{
KubeProxy: cluster.Spec.KubeProxy,
KubeProxy: &kubeProxy,
}

flags, _ := flagbuilder.BuildFlagsList(cluster.Spec.KubeProxy)
flags, _ := flagbuilder.BuildFlagsList(&kubeProxy)

flags = append(flags, []string{
"--kubeconfig=/var/lib/kube-proxy/kubeconfig",
Expand All @@ -70,7 +69,6 @@ func TestKubeProxyBuilder_buildPod(t *testing.T) {
"Setup KubeProxy for kubernetes version 1.20",
fields{
&NodeupModelContext{
Cluster: cluster,
NodeupConfig: nodeupConfig,
kubernetesVersion: semver.Version{Major: 1, Minor: 20},
},
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/kube_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (b *KubeSchedulerBuilder) Build(c *fi.NodeupModelBuilderContext) error {
return nil
}

kubeScheduler := *b.Cluster.Spec.KubeScheduler
kubeScheduler := b.NodeupConfig.ControlPlaneConfig.KubeScheduler

if err := b.writeServerCertificate(c, &kubeScheduler); err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions nodeup/pkg/model/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ func TestTaintsApplied(t *testing.T) {

for _, g := range tests {
cluster := &kops.Cluster{Spec: kops.ClusterSpec{
KubernetesVersion: g.version,
KubeAPIServer: &kops.KubeAPIServerConfig{},
KubernetesVersion: g.version,
KubeAPIServer: &kops.KubeAPIServerConfig{},
KubeControllerManager: &kops.KubeControllerManagerConfig{},
KubeScheduler: &kops.KubeSchedulerConfig{},
}}
input := testutils.BuildMinimalMasterInstanceGroup("eu-central-1a")
input.Spec.Taints = g.taints
Expand All @@ -69,7 +71,6 @@ func TestTaintsApplied(t *testing.T) {
config, bootConfig := nodeup.NewConfig(cluster, ig)
b := &KubeletBuilder{
&NodeupModelContext{
Cluster: cluster,
BootConfig: bootConfig,
NodeupConfig: config,
},
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type Config struct {

// APIServerConfig is additional configuration for nodes running an APIServer.
APIServerConfig *APIServerConfig `json:",omitempty"`
// ControlPlaneConfig is additional configuration for control-plane nodes.
ControlPlaneConfig *ControlPlaneConfig `json:",omitempty"`
// GossipConfig is configuration for gossip DNS.
GossipConfig *kops.GossipConfig `json:",omitempty"`
// DNSZone is the DNS zone we should use when configuring DNS.
Expand Down Expand Up @@ -190,6 +192,14 @@ type APIServerConfig struct {
ServiceAccountPublicKeys string
}

// ControlPlaneConfig is additional configuration for control-plane nodes.
type ControlPlaneConfig struct {
// KubeControllerManager is the configuration for the kube-controller-manager.
KubeControllerManager kops.KubeControllerManagerConfig
// KubeScheduler is the configuration for the kube-scheduler.
KubeScheduler kops.KubeSchedulerConfig
}

func NewConfig(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) (*Config, *BootConfig) {
role := instanceGroup.Spec.Role

Expand Down Expand Up @@ -341,6 +351,13 @@ func NewConfig(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) (*Confi
config.GossipConfig = cluster.Spec.GossipConfig
}

if instanceGroup.IsControlPlane() {
config.ControlPlaneConfig = &ControlPlaneConfig{
KubeControllerManager: *cluster.Spec.KubeControllerManager,
KubeScheduler: *cluster.Spec.KubeScheduler,
}
}

if len(instanceGroup.Spec.SysctlParameters) > 0 {
config.SysctlParameters = append(config.SysctlParameters,
"# Custom sysctl parameters from instance group spec",
Expand Down

0 comments on commit e317648

Please sign in to comment.