Skip to content

Commit

Permalink
Merge pull request #16768 from justinsb/make_options_builder_use_cluster
Browse files Browse the repository at this point in the history
refactor: OptionsBuilder works on kops.Cluster
  • Loading branch information
k8s-ci-robot authored Aug 25, 2024
2 parents 206f9fc + 29d6fd8 commit 388b0a2
Show file tree
Hide file tree
Showing 34 changed files with 126 additions and 124 deletions.
6 changes: 3 additions & 3 deletions pkg/model/components/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type KubeAPIServerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &KubeAPIServerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KubeAPIServerOptionsBuilder{}

// BuildOptions is responsible for filling in the default settings for the kube apiserver
func (b *KubeAPIServerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KubeAPIServerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
if clusterSpec.KubeAPIServer == nil {
clusterSpec.KubeAPIServer = &kops.KubeAPIServerConfig{}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type AWSOptionsBuilder struct {
OptionsContext *OptionsContext
}

var _ loader.OptionsBuilder = &AWSOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &AWSOptionsBuilder{}

func (b *AWSOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *AWSOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
aws := clusterSpec.CloudProvider.AWS
if aws == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/awscloudcontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type AWSCloudControllerManagerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &AWSCloudControllerManagerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &AWSCloudControllerManagerOptionsBuilder{}

// BuildOptions generates the configurations used for the AWS cloud controller manager manifest
func (b *AWSCloudControllerManagerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *AWSCloudControllerManagerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

if clusterSpec.GetCloudProvider() != kops.CloudProviderAWS {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/awsebscsidriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type AWSEBSCSIDriverOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &AWSEBSCSIDriverOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &AWSEBSCSIDriverOptionsBuilder{}

func (b *AWSEBSCSIDriverOptionsBuilder) BuildOptions(o interface{}) error {
aws := o.(*kops.ClusterSpec).CloudProvider.AWS
func (b *AWSEBSCSIDriverOptionsBuilder) BuildOptions(o *kops.Cluster) error {
aws := o.Spec.CloudProvider.AWS
if aws == nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type CalicoOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &CalicoOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &CalicoOptionsBuilder{}

func (b *CalicoOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *CalicoOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
c := clusterSpec.Networking.Calico
if c == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type CiliumOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &CiliumOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &CiliumOptionsBuilder{}

func (b *CiliumOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *CiliumOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
c := clusterSpec.Networking.Cilium
if c == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/cloudconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type CloudConfigurationOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &CloudConfigurationOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &CloudConfigurationOptionsBuilder{}

func (b *CloudConfigurationOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *CloudConfigurationOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
c := clusterSpec.CloudConfig
if c == nil {
c = &kops.CloudConfiguration{}
Expand Down
11 changes: 6 additions & 5 deletions pkg/model/components/cloudconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func TestCloudConfigurationOptionsBuilder(t *testing.T) {
},
} {
t.Run(test.description, func(t *testing.T) {
spec := kopsapi.ClusterSpec{
cluster := &kopsapi.Cluster{}
cluster.Spec = kopsapi.ClusterSpec{
CloudConfig: &kopsapi.CloudConfiguration{},
CloudProvider: kopsapi.CloudProviderSpec{
Openstack: &kopsapi.OpenstackSpec{
Expand All @@ -102,15 +103,15 @@ func TestCloudConfigurationOptionsBuilder(t *testing.T) {
},
}
if p := test.generalManageSCs; p != nil {
spec.CloudConfig.ManageStorageClasses = p
cluster.Spec.CloudConfig.ManageStorageClasses = p
}
if p := test.openStackManageSCs; p != nil {
spec.CloudProvider.Openstack.BlockStorage.CreateStorageClass = p
cluster.Spec.CloudProvider.Openstack.BlockStorage.CreateStorageClass = p
}
if err := ob.BuildOptions(&spec); err != nil {
if err := ob.BuildOptions(cluster); err != nil {
t.Fatalf("failed to build options: %v", err)
}
if want, got := test.expectedGeneralManageSCs, spec.CloudConfig.ManageStorageClasses; (want == nil) != (got == nil) || (got != nil && *got != *want) {
if want, got := test.expectedGeneralManageSCs, cluster.Spec.CloudConfig.ManageStorageClasses; (want == nil) != (got == nil) || (got != nil && *got != *want) {
switch {
case want == nil:
t.Errorf("spec.cloudConfig.manageStorageClasses: want nil, got %t", *got)
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/clusterautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type ClusterAutoscalerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &ClusterAutoscalerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &ClusterAutoscalerOptionsBuilder{}

func (b *ClusterAutoscalerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *ClusterAutoscalerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
cas := clusterSpec.ClusterAutoscaler
if cas == nil || !fi.ValueOf(cas.Enabled) {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type ContainerdOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &ContainerdOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &ContainerdOptionsBuilder{}

// BuildOptions is responsible for filling in the default setting for containerd daemon
func (b *ContainerdOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *ContainerdOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

if clusterSpec.Containerd == nil {
clusterSpec.Containerd = &kops.ContainerdConfig{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/containerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Test_Build_Containerd_Supported_Version(t *testing.T) {
},
}

err = ob.BuildOptions(&c.Spec)
err = ob.BuildOptions(c)
if err != nil {
t.Fatalf("unexpected error from BuildOptions: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type DefaultsOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &DefaultsOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &DefaultsOptionsBuilder{}

// BuildOptions is responsible for cluster options
func (b *DefaultsOptionsBuilder) BuildOptions(o interface{}) error {
options := o.(*kops.ClusterSpec)
func (b *DefaultsOptionsBuilder) BuildOptions(o *kops.Cluster) error {
options := &o.Spec

if options.ClusterDNSDomain == "" {
options.ClusterDNSDomain = "cluster.local"
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type DiscoveryOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &DiscoveryOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &DiscoveryOptionsBuilder{}

func (b *DiscoveryOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *DiscoveryOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

if clusterSpec.KubeAPIServer == nil {
clusterSpec.KubeAPIServer = &kops.KubeAPIServerConfig{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type EtcdOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &EtcdOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &EtcdOptionsBuilder{}

const (
DefaultEtcd3Version_1_22 = "3.5.13"
)

// BuildOptions is responsible for filling in the defaults for the etcd cluster model
func (b *EtcdOptionsBuilder) BuildOptions(o interface{}) error {
spec := o.(*kops.ClusterSpec)
func (b *EtcdOptionsBuilder) BuildOptions(o *kops.Cluster) error {
spec := &o.Spec

for i := range spec.EtcdClusters {
c := &spec.EtcdClusters[i]
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/etcdmanager/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type EtcdManagerOptionsBuilder struct {
*components.OptionsContext
}

var _ loader.OptionsBuilder = &EtcdManagerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &EtcdManagerOptionsBuilder{}

// BuildOptions generates the configurations used to create etcd manager manifest
func (b *EtcdManagerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *EtcdManagerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

for i := range clusterSpec.EtcdClusters {
etcdCluster := &clusterSpec.EtcdClusters[i]
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/gcpcloudcontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type GCPCloudControllerManagerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = (*GCPCloudControllerManagerOptionsBuilder)(nil)
var _ loader.ClusterOptionsBuilder = (*GCPCloudControllerManagerOptionsBuilder)(nil)

func (b *GCPCloudControllerManagerOptionsBuilder) BuildOptions(options interface{}) error {
clusterSpec := options.(*kops.ClusterSpec)
func (b *GCPCloudControllerManagerOptionsBuilder) BuildOptions(options *kops.Cluster) error {
clusterSpec := &options.Spec

if clusterSpec.GetCloudProvider() != kops.CloudProviderGCE {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/gcppdcsidriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type GCPPDCSIDriverOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &GCPPDCSIDriverOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &GCPPDCSIDriverOptionsBuilder{}

func (b *GCPPDCSIDriverOptionsBuilder) BuildOptions(o interface{}) error {
gce := o.(*kops.ClusterSpec).CloudProvider.GCE
func (b *GCPPDCSIDriverOptionsBuilder) BuildOptions(o *kops.Cluster) error {
gce := o.Spec.CloudProvider.GCE
if gce == nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/hetznercloudcontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type HetznerCloudControllerManagerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &HetznerCloudControllerManagerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &HetznerCloudControllerManagerOptionsBuilder{}

// BuildOptions generates the configurations used for the Hetzner cloud controller manager manifest
func (b *HetznerCloudControllerManagerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *HetznerCloudControllerManagerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

if clusterSpec.GetCloudProvider() != kops.CloudProviderHetzner {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/karpenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type KarpenterOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &KarpenterOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KarpenterOptionsBuilder{}

func (b *KarpenterOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KarpenterOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
c := clusterSpec.Karpenter
if c == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubecontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type KubeControllerManagerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &KubeControllerManagerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KubeControllerManagerOptionsBuilder{}

// BuildOptions generates the configurations used to create kubernetes controller manager manifest
func (b *KubeControllerManagerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KubeControllerManagerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
if clusterSpec.KubeControllerManager == nil {
clusterSpec.KubeControllerManager = &kops.KubeControllerManagerConfig{}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubecontrollermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Test_Build_KCM_Builder(t *testing.T) {
},
}

err := kcm.BuildOptions(&c.Spec)
err := kcm.BuildOptions(c)
if err != nil {
t.Fatalf("unexpected error from BuildOptions %s", err)
}
Expand All @@ -82,7 +82,7 @@ func Test_Build_KCM_Builder_Change_Duration(t *testing.T) {

c.Spec.KubeControllerManager.AttachDetachReconcileSyncPeriod.Duration = time.Minute * 5

err := kcm.BuildOptions(&c.Spec)
err := kcm.BuildOptions(c)
if err != nil {
t.Fatalf("unexpected error from BuildOptions %s", err)
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func Test_Build_KCM_Builder_CIDR_Mask_Size(t *testing.T) {
ClusterCIDR: tc.ClusterCIDR,
}

err := kcm.BuildOptions(&c.Spec)
err := kcm.BuildOptions(c)
require.NoError(t, err)

assert.Equal(t, tc.ExpectedMaskSize, c.Spec.KubeControllerManager.NodeCIDRMaskSize)
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubedns.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type KubeDnsOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &KubeDnsOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KubeDnsOptionsBuilder{}

// BuildOptions fills in the kubedns model
func (b *KubeDnsOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KubeDnsOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

if clusterSpec.KubeDNS == nil {
clusterSpec.KubeDNS = &kops.KubeDNSConfig{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type KubeletOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &KubeletOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KubeletOptionsBuilder{}

// BuildOptions is responsible for filling the defaults for the kubelet
func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KubeletOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec

if clusterSpec.Kubelet == nil {
clusterSpec.Kubelet = &kops.KubeletConfigSpec{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func buildOptions(cluster *kops.Cluster) error {
},
}

err = builder.BuildOptions(&cluster.Spec)
err = builder.BuildOptions(cluster)
if err != nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubeproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type KubeProxyOptionsBuilder struct {
Context *OptionsContext
}

var _ loader.OptionsBuilder = &KubeProxyOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KubeProxyOptionsBuilder{}

func (b *KubeProxyOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KubeProxyOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
if clusterSpec.KubeProxy == nil {
clusterSpec.KubeProxy = &kops.KubeProxyConfig{}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/components/kubescheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type KubeSchedulerOptionsBuilder struct {
*OptionsContext
}

var _ loader.OptionsBuilder = &KubeSchedulerOptionsBuilder{}
var _ loader.ClusterOptionsBuilder = &KubeSchedulerOptionsBuilder{}

func (b *KubeSchedulerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
func (b *KubeSchedulerOptionsBuilder) BuildOptions(o *kops.Cluster) error {
clusterSpec := &o.Spec
if clusterSpec.KubeScheduler == nil {
clusterSpec.KubeScheduler = &kops.KubeSchedulerConfig{}
}
Expand Down
Loading

0 comments on commit 388b0a2

Please sign in to comment.