Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/cloud/aws/assets/validating-admission-policy-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: openshift-cloud-controller-manager-cloud-provider-aws
spec:
policyName: openshift-cloud-controller-manager-cloud-provider-aws
validationActions: ["Deny"]
20 changes: 20 additions & 0 deletions pkg/cloud/aws/assets/validating-admission-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: openshift-cloud-controller-manager-cloud-provider-aws
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["UPDATE"]
resources: ["services"]
validations:
- expression: |
(has(object.metadata.annotations) && 'service.beta.kubernetes.io/aws-load-balancer-type' in object.metadata.annotations) ==
(has(oldObject.metadata.annotations) && 'service.beta.kubernetes.io/aws-load-balancer-type' in oldObject.metadata.annotations) &&
(has(object.metadata.annotations) && 'service.beta.kubernetes.io/aws-load-balancer-type' in object.metadata.annotations ?
object.metadata.annotations['service.beta.kubernetes.io/aws-load-balancer-type'] == oldObject.metadata.annotations['service.beta.kubernetes.io/aws-load-balancer-type'] : true)
message: "The annotation 'service.beta.kubernetes.io/aws-load-balancer-type' may not be added, removed, or have its value changed. Changing the type of an existing load balancer is not supported."
reason: Invalid
3 changes: 3 additions & 0 deletions pkg/cloud/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/asaskevich/govalidator"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -20,6 +21,8 @@ var (

templates = []common.TemplateSource{
{ReferenceObject: &appsv1.Deployment{}, EmbedFsPath: "assets/deployment.yaml"},
{ReferenceObject: &admissionregistrationv1.ValidatingAdmissionPolicy{}, EmbedFsPath: "assets/validating-admission-policy.yaml"},
{ReferenceObject: &admissionregistrationv1.ValidatingAdmissionPolicyBinding{}, EmbedFsPath: "assets/validating-admission-policy-binding.yaml"},
}
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestResourcesRenderingSmoke(t *testing.T) {
}

resources := assets.GetRenderedResources()
assert.Len(t, resources, 1)
assert.Len(t, resources, 3)
})
}
}
18 changes: 12 additions & 6 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,23 @@ func TestGetResources(t *testing.T) {
}{{
name: "AWS resources returned as expected",
testPlatform: platformsMap[string(configv1.AWSPlatformType)],
expectedResourceCount: 2,
expectedResourceCount: 4,
expectedResourcesKindName: []string{
"Deployment/aws-cloud-controller-manager",
"ValidatingAdmissionPolicy/openshift-cloud-controller-manager-cloud-provider-aws",
"ValidatingAdmissionPolicyBinding/openshift-cloud-controller-manager-cloud-provider-aws",
"PodDisruptionBudget/aws-cloud-controller-manager",
},
}, {
name: "AWS resources returned as expected with single node cluster",
testPlatform: platformsMap[string(configv1.AWSPlatformType)],
expectedResourceCount: 1,
singleReplica: true,
expectedResourcesKindName: []string{"Deployment/aws-cloud-controller-manager"},
name: "AWS resources returned as expected with single node cluster",
testPlatform: platformsMap[string(configv1.AWSPlatformType)],
expectedResourceCount: 3,
singleReplica: true,
expectedResourcesKindName: []string{
"Deployment/aws-cloud-controller-manager",
"ValidatingAdmissionPolicy/openshift-cloud-controller-manager-cloud-provider-aws",
"ValidatingAdmissionPolicyBinding/openshift-cloud-controller-manager-cloud-provider-aws",
},
}, {
name: "OpenStack resources returned as expected",
testPlatform: platformsMap[string(configv1.OpenStackPlatformType)],
Expand Down