Skip to content

Commit

Permalink
Reuse logic for checking if CNI network plugins need to be installed
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Jan 3, 2025
1 parent 284e0f7 commit 216af9a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 1 addition & 3 deletions nodeup/pkg/model/networking/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ var _ fi.NodeupModelBuilder = &CommonBuilder{}

// Build is responsible for copying the common CNI binaries
func (b *CommonBuilder) Build(c *fi.NodeupModelBuilderContext) error {
if b.NodeupConfig.Networking.AmazonVPC == nil &&
b.NodeupConfig.Networking.Calico == nil &&
b.NodeupConfig.Networking.Cilium == nil {
if b.NodeupConfig.InstallCNIAssets {
if err := b.AddCNIBinAssets(c); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,12 @@ func (c *Cluster) UsesNoneDNS() bool {
return false
}

func (c *Cluster) InstallCNIAssets() bool {
return c.Spec.Networking.AmazonVPC == nil &&
c.Spec.Networking.Calico == nil &&
c.Spec.Networking.Cilium == nil
}

func (c *Cluster) APIInternalName() string {
return "api.internal." + c.ObjectMeta.Name
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/apis/kops/model/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func (m *instanceGroupModel) GetCloudProvider() kops.CloudProviderID {
}

func (m *instanceGroupModel) InstallCNIAssets() bool {
return m.cluster.Spec.Networking.AmazonVPC == nil &&
m.cluster.Spec.Networking.Calico == nil &&
m.cluster.Spec.Networking.Cilium == nil
return m.cluster.InstallCNIAssets()
}

func (m *instanceGroupModel) RawClusterSpec() *kops.ClusterSpec {
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type Config struct {
KubeProxy *kops.KubeProxyConfig
// Networking configures networking.
Networking kops.NetworkingSpec
// InstallCNIAssets specifies that the CNI network plugins need to be installed.
InstallCNIAssets bool `json:",omitempty"`
// UseCiliumEtcd is true when a Cilium etcd cluster is present.
UseCiliumEtcd bool `json:",omitempty"`
// UsesKubenet specifies that the CNI is derived from Kubenet.
Expand Down Expand Up @@ -297,6 +299,10 @@ func NewConfig(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) (*Confi
config.UpdatePolicy = kops.UpdatePolicyAutomatic
}

if cluster.InstallCNIAssets() {
config.InstallCNIAssets = true
}

if cluster.Spec.Networking.AmazonVPC != nil {
config.Networking.AmazonVPC = &kops.AmazonVPCNetworkingSpec{}
config.DefaultMachineType = aws.String(strings.Split(instanceGroup.Spec.MachineType, ",")[0])
Expand Down

0 comments on commit 216af9a

Please sign in to comment.