Skip to content

Commit

Permalink
Merge pull request #15872 from johngmyers/aws-ccm-always
Browse files Browse the repository at this point in the history
Remove dead code for in-tree CCM
  • Loading branch information
k8s-ci-robot authored Sep 5, 2023
2 parents efab9bc + edd3d0b commit 92c0f48
Show file tree
Hide file tree
Showing 555 changed files with 384 additions and 790 deletions.
3 changes: 0 additions & 3 deletions cmd/kops-controller/pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type ServerOptions struct {
SigningCAs []string `json:"signingCAs"`
// CertNames is the list of active certificate names.
CertNames []string `json:"certNames"`

// UseInstanceIDForNodeName uses the instance ID instead of the hostname for the node name.
UseInstanceIDForNodeName bool `json:"useInstanceIDForNodeName,omitempty"`
}

type ServerProviderOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops-controller/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *Server) bootstrap(w http.ResponseWriter, r *http.Request) {

ctx := r.Context()

id, err := s.verifier.VerifyToken(ctx, r, r.Header.Get("Authorization"), body, s.opt.Server.UseInstanceIDForNodeName)
id, err := s.verifier.VerifyToken(ctx, r, r.Header.Get("Authorization"), body)
if err != nil {
// means that we should exit nodeup gracefully
if err == bootstrap.ErrAlreadyExists {
Expand Down
4 changes: 2 additions & 2 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ spec:
driver
properties:
enabled:
description: 'Enabled enables the AWS EBS CSI driver Default:
false'
description: 'Enabled enables the AWS EBS CSI driver. Can
only be set to true. Default: true'
type: boolean
managed:
description: Managed controls if aws-ebs-csi-driver is manged
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func (b *KubeletBuilder) kubeletNames() ([]string, error) {
return nil, fmt.Errorf("error describing instances: %v", err)
}

return awsup.GetInstanceCertificateNames(result, b.NodeupConfig.UseInstanceIDForNodeName)
return awsup.GetInstanceCertificateNames(result)
}

func (b *KubeletBuilder) buildCgroupService(name string) *nodetasks.Service {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@ type CloudConfiguration struct {

// EBSCSIDriverSpec is the config for the AWS EBS CSI driver
type EBSCSIDriverSpec struct {
// Enabled enables the AWS EBS CSI driver
// Default: false
Enabled *bool `json:"enabled,omitempty"`
// Enabled enables the AWS EBS CSI driver. Can only be set to true.
// Default: true
Enabled *bool `json:"-"`

// Managed controls if aws-ebs-csi-driver is manged and deployed by kOps.
// The deployment of aws-ebs-csi-driver is skipped if this is set to false.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,8 @@ type CloudConfiguration struct {

// EBSCSIDriverSpec is the config for the AWS EBS CSI driver
type EBSCSIDriverSpec struct {
// Enabled enables the AWS EBS CSI driver
// Default: false
// Enabled enables the AWS EBS CSI driver. Can only be set to true.
// Default: true
Enabled *bool `json:"enabled,omitempty"`

// Managed controls if aws-ebs-csi-driver is manged and deployed by kOps.
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/kops/v1alpha3/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,8 @@ type CloudConfiguration struct {

// EBSCSIDriverSpec is the config for the AWS EBS CSI driver
type EBSCSIDriverSpec struct {
// Enabled enables the AWS EBS CSI driver
// Default: false
Enabled *bool `json:"enabled,omitempty"`
// Enabled enables the AWS EBS CSI driver.
Enabled *bool `json:"-"`

// Managed controls if aws-ebs-csi-driver is manged and deployed by kOps.
// The deployment of aws-ebs-csi-driver is skipped if this is set to false.
Expand Down
23 changes: 5 additions & 18 deletions pkg/apis/kops/validation/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func awsValidateCluster(c *kops.Cluster, strict bool) field.ErrorList {
allErrs = append(allErrs, awsValidateLoadBalancerSubnets(lbPath.Child("subnets"), c.Spec)...)
}

allErrs = append(allErrs, awsValidateExternalCloudControllerManager(c)...)
allErrs = append(allErrs, awsValidateEBSCSIDriver(c)...)

if c.Spec.Authentication != nil && c.Spec.Authentication.AWS != nil {
allErrs = append(allErrs, awsValidateIAMAuthenticator(field.NewPath("spec", "authentication", "aws"), c.Spec.Authentication.AWS)...)
Expand All @@ -63,16 +63,12 @@ func awsValidateCluster(c *kops.Cluster, strict bool) field.ErrorList {
return allErrs
}

func awsValidateExternalCloudControllerManager(cluster *kops.Cluster) (allErrs field.ErrorList) {
func awsValidateEBSCSIDriver(cluster *kops.Cluster) (allErrs field.ErrorList) {
c := cluster.Spec

if c.ExternalCloudControllerManager == nil {
return allErrs
}
fldPath := field.NewPath("spec", "externalCloudControllerManager")
if !hasAWSEBSCSIDriver(c) {
allErrs = append(allErrs, field.Forbidden(fldPath,
"AWS external CCM cannot be used without enabling spec.cloudProvider.aws.ebsCSIDriverSpec."))
fldPath := field.NewPath("spec", "cloudProvider", "aws", "ebsCSIDriver", "enabled")
if c.CloudProvider.AWS.EBSCSIDriver != nil && c.CloudProvider.AWS.EBSCSIDriver.Enabled != nil && !*c.CloudProvider.AWS.EBSCSIDriver.Enabled {
allErrs = append(allErrs, field.Forbidden(fldPath, "must not be disabled"))
}
return allErrs
}
Expand Down Expand Up @@ -397,15 +393,6 @@ func awsValidateIAMAuthenticator(fieldPath *field.Path, spec *kops.AWSAuthentica
return allErrs
}

func hasAWSEBSCSIDriver(c kops.ClusterSpec) bool {
// EBSCSIDriverSpec will have a default value, so if this is all false, it will be populated on next pass
if c.CloudProvider.AWS.EBSCSIDriver == nil || c.CloudProvider.AWS.EBSCSIDriver.Enabled == nil {
return true
}

return *c.CloudProvider.AWS.EBSCSIDriver.Enabled
}

func awsValidateAdditionalRoutes(fieldPath *field.Path, routes []kops.RouteSpec, networkCIDRs []*net.IPNet) field.ErrorList {
allErrs := field.ErrorList{}

Expand Down
12 changes: 9 additions & 3 deletions pkg/apis/kops/validation/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"k8s.io/kops/pkg/apis/kops"
)

func TestAWSValidateExternalCloudConfig(t *testing.T) {
func TestAWSValidateEBSCSIDriver(t *testing.T) {
grid := []struct {
Input kops.ClusterSpec
ExpectedErrors []string
Expand All @@ -49,7 +49,7 @@ func TestAWSValidateExternalCloudConfig(t *testing.T) {
},
},
},
ExpectedErrors: []string{"Forbidden::spec.externalCloudControllerManager"},
ExpectedErrors: []string{"Forbidden::spec.cloudProvider.aws.ebsCSIDriver.enabled"},
},
{
Input: kops.ClusterSpec{
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestAWSValidateExternalCloudConfig(t *testing.T) {
cluster := &kops.Cluster{
Spec: g.Input,
}
errs := awsValidateExternalCloudControllerManager(cluster)
errs := awsValidateEBSCSIDriver(cluster)

testErrors(t, g.Input, errs, g.ExpectedErrors)
}
Expand Down Expand Up @@ -585,6 +585,9 @@ func TestLoadBalancerSubnets(t *testing.T) {
Type: kops.LoadBalancerTypeInternal,
},
},
CloudProvider: kops.CloudProviderSpec{
AWS: &kops.AWSSpec{},
},
},
}
if test.class != nil {
Expand Down Expand Up @@ -668,6 +671,9 @@ func TestAWSAuthentication(t *testing.T) {
IdentityMappings: test.identityMappings,
},
},
CloudProvider: kops.CloudProviderSpec{
AWS: &kops.AWSSpec{},
},
},
}
errs := awsValidateCluster(&cluster, true)
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ func validateClusterSpec(spec *kops.ClusterSpec, c *kops.Cluster, fieldPath *fie
allErrs = append(allErrs, validateKubeAPIServer(spec.KubeAPIServer, c, fieldPath.Child("kubeAPIServer"), strict)...)
}

if spec.ExternalCloudControllerManager == nil && spec.IsIPv6Only() {
allErrs = append(allErrs, field.Required(fieldPath.Child("cloudControllerManager"), "IPv6 requires external Cloud Controller Manager"))
}

if spec.KubeProxy != nil {
allErrs = append(allErrs, validateKubeProxy(spec.KubeProxy, fieldPath.Child("kubeProxy"))...)
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ type Config struct {
ElbSecurityGroup *string `json:"elbSecurityGroup,omitempty"`
// NodeIPFamilies controls the IP families reported for each node.
NodeIPFamilies []string `json:"nodeIPFamilies,omitempty"`
// UseInstanceIDForNodeName uses the instance ID instead of the hostname for the node name.
UseInstanceIDForNodeName bool `json:"useInstanceIDForNodeName,omitempty"`
// WarmPoolImages are the container images to pre-pull during instance pre-initialization
WarmPoolImages []string `json:"warmPoolImages,omitempty"`

Expand Down Expand Up @@ -336,10 +334,6 @@ func NewConfig(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) (*Confi
config.Networking.KubeRouter = &kops.KuberouterNetworkingSpec{}
}

if UsesInstanceIDForNodeName(cluster) {
config.UseInstanceIDForNodeName = true
}

if instanceGroup.Spec.Kubelet != nil {
config.KubeletConfig = *instanceGroup.Spec.Kubelet
}
Expand Down Expand Up @@ -454,10 +448,6 @@ func buildKubeProxy(cluster *kops.Cluster, instanceGroup *kops.InstanceGroup) *k
return config
}

func UsesInstanceIDForNodeName(cluster *kops.Cluster) bool {
return cluster.Spec.ExternalCloudControllerManager != nil && cluster.Spec.GetCloudProvider() == kops.CloudProviderAWS
}

func filterFileAssets(f []kops.FileAssetSpec, role kops.InstanceGroupRole) []kops.FileAssetSpec {
var fileAssets []kops.FileAssetSpec
for _, fileAsset := range f {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bootstrap/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ type VerifyResult struct {

// Verifier verifies authentication credentials for requests.
type Verifier interface {
VerifyToken(ctx context.Context, rawRequest *http.Request, token string, body []byte, useInstanceIDForNodeName bool) (*VerifyResult, error)
VerifyToken(ctx context.Context, rawRequest *http.Request, token string, body []byte) (*VerifyResult, error)
}
2 changes: 1 addition & 1 deletion pkg/model/components/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (b *KubeAPIServerOptionsBuilder) BuildOptions(o interface{}) error {
c.FeatureGates = make(map[string]string)
}

if clusterSpec.CloudProvider.AWS != nil && clusterSpec.CloudProvider.AWS.EBSCSIDriver != nil && fi.ValueOf(clusterSpec.CloudProvider.AWS.EBSCSIDriver.Enabled) {
if clusterSpec.CloudProvider.AWS != nil {

if _, found := c.FeatureGates["InTreePluginAWSUnregister"]; !found {
c.FeatureGates["InTreePluginAWSUnregister"] = "true"
Expand Down
4 changes: 0 additions & 4 deletions pkg/model/components/awscloudcontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ func (b *AWSCloudControllerManagerOptionsBuilder) BuildOptions(o interface{}) er

eccm := clusterSpec.ExternalCloudControllerManager

if eccm == nil {
return nil
}

// No significant downside to always doing a leader election.
// Also, having multiple control plane nodes requires leader election.
eccm.LeaderElection = &kops.LeaderElectionConfiguration{LeaderElect: fi.PtrTo(true)}
Expand Down
4 changes: 0 additions & 4 deletions pkg/model/components/awsebscsidriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func (b *AWSEBSCSIDriverOptionsBuilder) BuildOptions(o interface{}) error {
}
c := aws.EBSCSIDriver

if !fi.ValueOf(c.Enabled) {
return nil
}

if c.Version == nil {
version := "v1.14.1"
c.Version = &version
Expand Down
4 changes: 0 additions & 4 deletions pkg/model/components/gcpcloudcontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func (b *GCPCloudControllerManagerOptionsBuilder) BuildOptions(options interface

ccmConfig := clusterSpec.ExternalCloudControllerManager

if ccmConfig == nil {
return nil
}

// No significant downside to always doing a leader election.
// Also, having multiple control plane nodes requires leader election.
ccmConfig.LeaderElection = &kops.LeaderElectionConfiguration{LeaderElect: fi.PtrTo(true)}
Expand Down
10 changes: 1 addition & 9 deletions pkg/model/components/kubecontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ func (b *KubeControllerManagerOptionsBuilder) BuildOptions(o interface{}) error
kcm.ClusterName = b.ClusterName
kcm.CloudProvider = "external"

if clusterSpec.ExternalCloudControllerManager == nil {
if kcm.CloudProvider == "aws" || kcm.CloudProvider == "gce" {
kcm.EnableLeaderMigration = fi.PtrTo(true)
}
} else {
kcm.CloudProvider = "external"
}

if kcm.LogLevel == 0 {
kcm.LogLevel = 2
}
Expand Down Expand Up @@ -151,7 +143,7 @@ func (b *KubeControllerManagerOptionsBuilder) BuildOptions(o interface{}) error
}
}

if clusterSpec.CloudProvider.AWS != nil && clusterSpec.CloudProvider.AWS.EBSCSIDriver != nil && fi.ValueOf(clusterSpec.CloudProvider.AWS.EBSCSIDriver.Enabled) {
if clusterSpec.CloudProvider.AWS != nil {

if kcm.FeatureGates == nil {
kcm.FeatureGates = make(map[string]string)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec.Kubelet.FeatureGates = make(map[string]string)
}

if clusterSpec.CloudProvider.AWS != nil && clusterSpec.CloudProvider.AWS.EBSCSIDriver != nil && fi.ValueOf(clusterSpec.CloudProvider.AWS.EBSCSIDriver.Enabled) {
if clusterSpec.CloudProvider.AWS != nil {
if _, found := clusterSpec.Kubelet.FeatureGates["CSIMigrationAWS"]; !found && b.IsKubernetesLT("1.27") {
clusterSpec.Kubelet.FeatureGates["CSIMigrationAWS"] = "true"
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/kubescheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (b *KubeSchedulerOptionsBuilder) BuildOptions(o interface{}) error {
}
}

if clusterSpec.CloudProvider.AWS != nil && clusterSpec.CloudProvider.AWS.EBSCSIDriver != nil && fi.ValueOf(clusterSpec.CloudProvider.AWS.EBSCSIDriver.Enabled) {
if clusterSpec.CloudProvider.AWS != nil {

if config.FeatureGates == nil {
config.FeatureGates = make(map[string]string)
Expand Down
32 changes: 1 addition & 31 deletions pkg/model/iam/iam_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,12 @@ func (r *NodeRoleMaster) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
// Protokube needs dns-controller permissions in instance role even if UseServiceAccountExternalPermissions.
AddDNSControllerPermissions(b, p)

// If cluster does not use external CCM, the master IAM Role needs CCM permissions
if b.Cluster.Spec.ExternalCloudControllerManager == nil {
AddCCMPermissions(p, b.Cluster.Spec.Networking.Kubenet != nil)
AddLegacyCCMPermissions(p)
}

if !b.UseServiceAccountExternalPermisssions {
esc := b.Cluster.Spec.SnapshotController != nil &&
fi.ValueOf(b.Cluster.Spec.SnapshotController.Enabled)
AddAWSEBSCSIDriverPermissions(p, esc)

if b.Cluster.Spec.ExternalCloudControllerManager != nil {
AddCCMPermissions(p, b.Cluster.Spec.Networking.Kubenet != nil)
}
AddCCMPermissions(p, b.Cluster.Spec.Networking.Kubenet != nil)

if c := b.Cluster.Spec.CloudProvider.AWS.LoadBalancerController; c != nil && fi.ValueOf(b.Cluster.Spec.CloudProvider.AWS.LoadBalancerController.Enabled) {
AddAWSLoadbalancerControllerPermissions(p, c.EnableWAF, c.EnableWAFv2, c.EnableShield)
Expand Down Expand Up @@ -826,28 +818,6 @@ func addEtcdManagerPermissions(p *Policy) {
)
}

func AddLegacyCCMPermissions(p *Policy) {
p.unconditionalAction.Insert(
"ec2:CreateSecurityGroup",
"ec2:CreateTags",
"elasticloadbalancing:CreateTargetGroup",
"elasticloadbalancing:AddTags",
"elasticloadbalancing:RegisterTargets",
"elasticloadbalancing:CreateListener",
"elasticloadbalancing:DeleteListener",
"elasticloadbalancing:ModifyListener",
"ec2:DescribeVolumes",
"ec2:ModifyInstanceAttribute",
"ec2:ModifyVolume",
"ec2:AttachVolume",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:DeleteRoute",
"ec2:DeleteSecurityGroup",
"ec2:DeleteVolume",
"ec2:DetachVolume",
)
}

func AddCCMPermissions(p *Policy, cloudRoutes bool) {
p.unconditionalAction.Insert(
"autoscaling:DescribeAutoScalingGroups",
Expand Down
1 change: 1 addition & 0 deletions pkg/model/iam/iam_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func TestPolicyGeneration(t *testing.T) {
},
},
},
ExternalCloudControllerManager: &kops.CloudControllerManagerConfig{},
Networking: kops.NetworkingSpec{
Kubenet: &kops.KubenetNetworkingSpec{},
},
Expand Down
Loading

0 comments on commit 92c0f48

Please sign in to comment.