Skip to content

Support security group names in VPC Resource controller #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions apis/vpcresources/v1beta1/securitygrouppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ type SecurityGroupPolicySpec struct {
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"`
ServiceAccountSelector *metav1.LabelSelector `json:"serviceAccountSelector,omitempty"`
SecurityGroups GroupIds `json:"securityGroups,omitempty"`
SecurityGroupNames GroupNames `json:"securityGroupNames,omitempty"`
}

// GroupNames contains the list of security group names that will be applied to the network interface of the pod matching the criteria.
type GroupNames struct {
// Groups is the list of EC2 Security Group Names that need to be applied to the ENI of a Pod.
// +kubebuilder:validation:MinItems=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have MinItems=0.
MinItems=1 would enforce that customers specify at least 1 SG name. What if they want to specify only SG IDs?

We need to enforce that both lists combined is not empty though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya thats a good call out, let me see what we can do here

Copy link
Contributor Author

@GnatorX GnatorX Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-empty check I believe is checked on CreateNetworkInterface. Do you have different place in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be good to include in CRD validation, let me see how to do this with kubebuilder.

// +kubebuilder:validation:MaxItems=5
GroupNames []string `json:"groupNames,omitempty"`
}

// GroupIds contains the list of security groups that will be applied to the network interface of the pod matching the criteria.
Expand All @@ -45,6 +54,7 @@ type ServiceAccountSelector struct {

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Security-Group-Ids",type=string,JSONPath=`.spec.securityGroups.groupIds`,description="The security group IDs to apply to the elastic network interface of pods that match this policy"
// +kubebuilder:printcolumn:name="Security-Group-Names",type=string,JSONPath=`.spec.securityGroups.groupNames`,description="The security group names to apply to the elastic network interface of pods that match this policy"
// +kubebuilder:resource:shortName=sgp

// Custom Resource Definition for applying security groups to pods
Expand Down
21 changes: 21 additions & 0 deletions apis/vpcresources/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ spec:
jsonPath: .spec.securityGroups.groupIds
name: Security-Group-Ids
type: string
- description: The security group names to apply to the elastic network interface
of pods that match this policy
jsonPath: .spec.securityGroups.groupNames
name: Security-Group-Names
type: string
name: v1beta1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -90,6 +95,20 @@ spec:
are ANDed.
type: object
type: object
securityGroupNames:
description: GroupNames contains the list of security group names
that will be applied to the network interface of the pod matching
the criteria.
properties:
groupNames:
description: Groups is the list of EC2 Security Group Names that
need to be applied to the ENI of a Pod.
items:
type: string
maxItems: 5
minItems: 1
type: array
type: object
securityGroups:
description: GroupIds contains the list of security groups that will
be applied to the network interface of the pod matching the criteria.
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func main() {
if err != nil {
setupLog.Error(err, "unable to create ec2 wrapper")
}
ec2APIHelper := ec2API.NewEC2APIHelper(ec2Wrapper, clusterName)
ec2APIHelper := ec2API.NewEC2APIHelper(ec2Wrapper, clusterName, vpcID)

sgpAPI := utils.NewSecurityGroupForPodsAPI(
mgr.GetClient(),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions mocks/amazon-vcp-resource-controller-k8s/pkg/node/mock_node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions mocks/amazon-vcp-resource-controller-k8s/pkg/pool/mock_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading