Skip to content

Commit

Permalink
add a new CRD to delegate vpc resource requests
Browse files Browse the repository at this point in the history
  • Loading branch information
haouc committed May 17, 2023
1 parent 0c6381a commit b9e7e1d
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 0 deletions.
54 changes: 54 additions & 0 deletions apis/vpcresources/v1alpha1/cninode_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// FeatureName is a type of feature name supported by EKS networking. It can be Security Group for Pods, custom networking, or others
type FeatureName string

const (
SGP FeatureName = "SecurityGroupsPerPod"
CustomNetworking FeatureName = "CustomNetworking"
)

// Important: Run "make" to regenerate code after modifying this file
// CNINodeSpec defines the desired state of VPCResourceRequest
type CNINodeSpec struct {
Features []FeatureName `json:"features,omitempty"`
}

type VPCResource string

// +kubebuilder:object:root=true
// Custom Resource Definition for Request to VPC resource controller
type CNINode struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CNINodeSpec `json:"spec,omitempty"`
}

// +kubebuilder:object:root=true
// VPCResourceRequestList contains a list of VPCResourceRequest
type CNINodeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CNINode `json:"items"`
}

func init() {
SchemeBuilder.Register(&CNINode{}, &CNINodeList{})
}
33 changes: 33 additions & 0 deletions apis/vpcresources/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

// Package v1beta1 contains API Schema definitions for the vpcresources v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=vpcresources.k8s.aws
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "vpcresources.k8s.aws", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
101 changes: 101 additions & 0 deletions apis/vpcresources/v1alpha1/zz_generated.deepcopy.go

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

56 changes: 56 additions & 0 deletions config/crd/bases/vpcresources.k8s.aws_cninodes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: cninodes.vpcresources.k8s.aws
spec:
group: vpcresources.k8s.aws
names:
kind: CNINode
listKind: CNINodeList
plural: cninodes
singular: cninode
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Custom Resource Definition for Request to VPC resource controller
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: 'Important: Run "make" to regenerate code after modifying
this file CNINodeSpec defines the desired state of VPCResourceRequest'
properties:
features:
items:
description: FeatureName is a type of feature name supported by
EKS networking. It can be Security Group for Pods, custom networking,
or others
type: string
type: array
type: object
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ rules:
- get
- list
- watch
- apiGroups:
- vpcresources.k8s.aws
resources:
- vpcresourcerequests
verbs:
- get
- list
- watch

---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func init() {
// +kubebuilder:rbac:groups=apps,resources=deployments,namespace=kube-system,resourceNames=vpc-resource-controller,verbs=get;list;watch
// +kubebuilder:rbac:groups=crd.k8s.amazonaws.com,resources=eniconfigs,verbs=get;list;watch
// +kubebuilder:rbac:groups=vpcresources.k8s.aws,resources=securitygrouppolicies,verbs=get;list;watch
// +kubebuilder:rbac:groups=vpcresources.k8s.aws,resources=vpcresourcerequests,verbs=get;list;watch

// Migration to leases based leader election
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,namespace=kube-system,verbs=create
Expand Down

0 comments on commit b9e7e1d

Please sign in to comment.