Skip to content

Commit a9d5c1e

Browse files
surajssdinvidian
authored andcommitted
Add feature gate BootstrapFormatIgnition
This commit adds the feature gate BootstrapFormatIgnition that will control the usage of field `ignition` in AWSMachine & AWSMachineTemplate and `s3Bucket` in AWSCluster. If user provides `ignition` field and/or `s3Bucket` without setting the feature gate then the webhook rejects the request with a validation error. Signed-off-by: Suraj Deshmukh <[email protected]>
1 parent 3156e2e commit a9d5c1e

File tree

9 files changed

+42
-4
lines changed

9 files changed

+42
-4
lines changed

api/v1beta1/awscluster_webhook_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import (
2525
"github.com/aws/aws-sdk-go/aws"
2626
. "github.com/onsi/gomega"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
utilfeature "k8s.io/component-base/featuregate/testing"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930

31+
"sigs.k8s.io/cluster-api-provider-aws/feature"
3032
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3133
utildefaulting "sigs.k8s.io/cluster-api/util/defaulting"
3234
)
@@ -223,6 +225,8 @@ func TestAWSCluster_ValidateCreate(t *testing.T) {
223225
}
224226
for _, tt := range tests {
225227
t.Run(tt.name, func(t *testing.T) {
228+
defer utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.BootstrapFormatIgnition, true)()
229+
226230
cluster := tt.cluster.DeepCopy()
227231
cluster.ObjectMeta = metav1.ObjectMeta{
228232
GenerateName: "cluster-",

api/v1beta1/awsmachine_webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
ctrl "sigs.k8s.io/controller-runtime"
2727
logf "sigs.k8s.io/controller-runtime/pkg/log"
2828
"sigs.k8s.io/controller-runtime/pkg/webhook"
29+
30+
"sigs.k8s.io/cluster-api-provider-aws/feature"
2931
)
3032

3133
// log is for logging in this package.
@@ -159,6 +161,12 @@ func (r *AWSMachine) ignitionEnabled() bool {
159161
func (r *AWSMachine) validateIgnitionAndCloudInit() field.ErrorList {
160162
var allErrs field.ErrorList
161163

164+
// Feature gate is not enabled but ignition is enabled then send a forbidden error.
165+
if !feature.Gates.Enabled(feature.BootstrapFormatIgnition) && r.ignitionEnabled() {
166+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "ignition"),
167+
"can be set only if the BootstrapFormatIgnition feature gate is enabled"))
168+
}
169+
162170
if r.ignitionEnabled() && r.cloudInitConfigured() {
163171
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "cloudInit"), "cannot be set if spec.ignition is set"))
164172
}

api/v1beta1/awsmachinetemplate_webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"k8s.io/apimachinery/pkg/util/validation/field"
2525
ctrl "sigs.k8s.io/controller-runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/webhook"
27+
28+
"sigs.k8s.io/cluster-api-provider-aws/feature"
2729
)
2830

2931
func (r *AWSMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
@@ -113,6 +115,12 @@ func (r *AWSMachineTemplate) ValidateCreate() error {
113115
allErrs = append(allErrs, r.validateRootVolume()...)
114116
allErrs = append(allErrs, r.validateNonRootVolumes()...)
115117

118+
// Feature gate is not enabled but ignition is enabled then send a forbidden error.
119+
if !feature.Gates.Enabled(feature.BootstrapFormatIgnition) && spec.Ignition != nil {
120+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "ignition"),
121+
"can be set only if the BootstrapFormatIgnition feature gate is enabled"))
122+
}
123+
116124
cloudInitConfigured := spec.CloudInit.SecureSecretsBackend != "" || spec.CloudInit.InsecureSkipSecretsManager
117125
if cloudInitConfigured && spec.Ignition != nil {
118126
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "template", "spec", "cloudInit"),

api/v1beta1/s3bucket.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"net"
2222

2323
"k8s.io/apimachinery/pkg/util/validation/field"
24+
25+
"sigs.k8s.io/cluster-api-provider-aws/feature"
2426
)
2527

2628
// Validate validates S3Bucket fields.
@@ -35,6 +37,12 @@ func (b *S3Bucket) Validate() []*field.Error {
3537
errs = append(errs, field.Required(field.NewPath("spec", "s3Bucket", "name"), "can't be empty"))
3638
}
3739

40+
// Feature gate is not enabled but ignition is enabled then send a forbidden error.
41+
if !feature.Gates.Enabled(feature.BootstrapFormatIgnition) {
42+
errs = append(errs, field.Forbidden(field.NewPath("spec", "s3Bucket"),
43+
"can be set only if the BootstrapFormatIgnition feature gate is enabled"))
44+
}
45+
3846
if b.ControlPlaneIAMInstanceProfile == "" {
3947
errs = append(errs,
4048
field.Required(field.NewPath("spec", "s3Bucket", "controlPlaneIAMInstanceProfiles"), "can't be empty"))

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec:
1919
containers:
2020
- args:
2121
- "--leader-elect"
22-
- "--feature-gates=EKS=${CAPA_EKS:=true},EKSEnableIAM=${CAPA_EKS_IAM:=false},EKSAllowAddRoles=${CAPA_EKS_ADD_ROLES:=false},EKSFargate=${EXP_EKS_FARGATE:=false},MachinePool=${EXP_MACHINE_POOL:=false},EventBridgeInstanceState=${EVENT_BRIDGE_INSTANCE_STATE:=false},AutoControllerIdentityCreator=${AUTO_CONTROLLER_IDENTITY_CREATOR:=true}"
22+
- "--feature-gates=EKS=${CAPA_EKS:=true},EKSEnableIAM=${CAPA_EKS_IAM:=false},EKSAllowAddRoles=${CAPA_EKS_ADD_ROLES:=false},EKSFargate=${EXP_EKS_FARGATE:=false},MachinePool=${EXP_MACHINE_POOL:=false},EventBridgeInstanceState=${EVENT_BRIDGE_INSTANCE_STATE:=false},AutoControllerIdentityCreator=${AUTO_CONTROLLER_IDENTITY_CREATOR:=true},BootstrapFormatIgnition=${EXP_BOOTSTRAP_FORMAT_IGNITION:=false}"
2323
- "--v=${CAPA_LOGLEVEL:=0}"
2424
- "--metrics-bind-addr=127.0.0.1:8080"
2525
image: controller:latest

docs/book/src/development/tilt-setup.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Next, create a `tilt-settings.json` file and place it in your local copy of `clu
5656
"AWS_B64ENCODED_CREDENTIALS": "W2RlZmFZSZnRg==",
5757
"EXP_EKS_FARGATE": "false",
5858
"CAPA_EKS_IAM": "false",
59-
"CAPA_EKS_ADD_ROLES": "false"
59+
"CAPA_EKS_ADD_ROLES": "false",
60+
"EXP_BOOTSTRAP_FORMAT_IGNITION": "true"
6061
},
6162
"extra_args": {
6263
"aws": ["--v=2"]
@@ -186,15 +187,15 @@ export EKS_KUBERNETES_VERSION=v1.15
186187
**Create CAPA managed workload cluster:**
187188

188189
```bash
189-
cat templates/cluster-template.yaml
190+
cat templates/cluster-template.yaml
190191
cat templates/cluster-template.yaml | $HOME/go/bin/envsubst > test-cluster.yaml
191192
kubectl apply -f test-cluster.yaml
192193
```
193194

194195
**Create EKS workload cluster:**
195196

196197
```bash
197-
cat templates/cluster-template-eks.yaml
198+
cat templates/cluster-template-eks.yaml
198199
cat templates/cluster-template-eks.yaml | $HOME/go/bin/envsubst > test-cluster.yaml
199200
kubectl apply -f test-cluster.yaml
200201
```

feature/feature.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const (
6262
// owner: @sedefsavas
6363
// alpha: v0.6
6464
AutoControllerIdentityCreator featuregate.Feature = "AutoControllerIdentityCreator"
65+
66+
// BootstrapFormatIgnition will allow an user to enable alternate machine bootstrap format, viz. Ignition.
67+
BootstrapFormatIgnition featuregate.Feature = "BootstrapFormatIgnition"
6568
)
6669

6770
func init() {
@@ -79,4 +82,5 @@ var defaultCAPAFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
7982
EventBridgeInstanceState: {Default: false, PreRelease: featuregate.Alpha},
8083
MachinePool: {Default: false, PreRelease: featuregate.Alpha},
8184
AutoControllerIdentityCreator: {Default: true, PreRelease: featuregate.Alpha},
85+
BootstrapFormatIgnition: {Default: false, PreRelease: featuregate.Alpha},
8286
}

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ func enableGates(ctx context.Context, mgr ctrl.Manager, awsServiceEndpoints []sc
392392
os.Exit(1)
393393
}
394394
}
395+
396+
if feature.Gates.Enabled(feature.BootstrapFormatIgnition) {
397+
setupLog.Info("Enabling Ignition support for machine bootstrap data")
398+
}
395399
}
396400
func initFlags(fs *pflag.FlagSet) {
397401
fs.StringVar(

test/e2e/data/e2e_conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ variables:
283283
# INIT_WITH_KUBERNETES_VERSION are only used by the clusterctl upgrade test to initialize
284284
# the management cluster to be upgraded.
285285
INIT_WITH_KUBERNETES_VERSION: "v1.21.6"
286+
EXP_BOOTSTRAP_FORMAT_IGNITION: "true"
286287

287288
intervals:
288289
default/wait-cluster: ["30m", "10s"]

0 commit comments

Comments
 (0)