-
Notifications
You must be signed in to change notification settings - Fork 260
[Multitenancy] : Add MT PodNetworkConfig CRD #2111
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ea5a879
Add MT PodNetworkConfig CRD
aggarwal0009 e82908a
fix comment typo
aggarwal0009 2b7c995
adding readme
aggarwal0009 c8aa4a7
remove reconciling status
aggarwal0009 0d81201
add comments
aggarwal0009 a3170f5
updated crd manifest
aggarwal0009 c30f7f7
address pr comments
aggarwal0009 f465c48
fix typo
aggarwal0009 0d4ed6d
update crdgen.yaml
aggarwal0009 f845f82
fix method name
aggarwal0009 21816ef
fix typo
aggarwal0009 32e26ee
update manifest indentation
aggarwal0009 0063bf6
update readme
aggarwal0009 344adc0
revert crdgen file
aggarwal0009 a519a22
removed unnecessary helper func from crd client
aggarwal0009 4f052d0
address pr comments
aggarwal0009 eff4dd8
update UUID to NCID for MPNC CRD
aggarwal0009 ca12e0f
address more pr comments
aggarwal0009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| .DEFAULT_GOAL = all | ||
|
|
||
| REPO_ROOT = $(shell git rev-parse --show-toplevel) | ||
| TOOLS_DIR = $(REPO_ROOT)/build/tools | ||
| TOOLS_BIN_DIR = $(REPO_ROOT)/build/tools/bin | ||
| CONTROLLER_GEN = $(TOOLS_BIN_DIR)/controller-gen | ||
|
|
||
| all: generate manifests | ||
|
|
||
| generate: $(CONTROLLER_GEN) | ||
| $(CONTROLLER_GEN) object paths="./..." | ||
|
|
||
| .PHONY: manifests | ||
| manifests: $(CONTROLLER_GEN) | ||
| mkdir -p manifests | ||
| $(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=manifests/ | ||
|
|
||
| $(CONTROLLER_GEN): | ||
| @make -C $(REPO_ROOT) $(CONTROLLER_GEN) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # MultitenantPodNetworkConfig CRDs | ||
|
|
||
| MTPNC objects represent the network configuration goal state for a pod running a multitenant networked container and are created and managed by control plane as part of the network configuration, during Pod lifecycle events. |
23 changes: 23 additions & 0 deletions
23
crd/multitenantpodnetworkconfig/api/v1alpha1/groupversion_info.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //go:build !ignore_uncovered | ||
| // +build !ignore_uncovered | ||
|
|
||
| // Package v1alpha1 contains API Schema definitions for the acn v1alpha1 API group | ||
| // +kubebuilder:object:generate=true | ||
| // +groupName=acn.azure.com | ||
| 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: "acn.azure.com", 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 | ||
| ) |
65 changes: 65 additions & 0 deletions
65
crd/multitenantpodnetworkconfig/api/v1alpha1/multitenantpodnetworkconfig.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //go:build !ignore_uncovered | ||
| // +build !ignore_uncovered | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // Important: Run "make" to regenerate code after modifying this file | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // MultitenantPodNetworkConfig is the Schema for the multitenantpodnetworkconfigs API | ||
| // +kubebuilder:resource:scope=Namespaced | ||
| // +kubebuilder:resource:shortName=mtpnc | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:metadata:labels=managed= | ||
| // +kubebuilder:metadata:labels=owner= | ||
| // +kubebuilder:printcolumn:name="PodNetworkInstance",type=string,JSONPath=`.spec.podNetworkInstance` | ||
| // +kubebuilder:printcolumn:name="PodName",type=string,JSONPath=`.spec.podName` | ||
| // +kubebuilder:printcolumn:name="NCID",type=string,JSONPath=`.status.ncID` | ||
| // +kubebuilder:printcolumn:name="PrimaryIP",type=string,JSONPath=`.status.primaryIP` | ||
| // +kubebuilder:printcolumn:name="MacAddress",type=string,JSONPath=`.status.macAddress` | ||
| // +kubebuilder:printcolumn:name="GatewayIP",type=string,JSONPath=`.status.gatewayIP` | ||
| type MultitenantPodNetworkConfig struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec MultitenantPodNetworkConfigSpec `json:"spec,omitempty"` | ||
| Status MultitenantPodNetworkConfigStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // MultitenantPodNetworkConfigList contains a list of PodNetworkConfig | ||
| type MultitenantPodNetworkConfigList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []MultitenantPodNetworkConfig `json:"items"` | ||
| } | ||
|
|
||
| // MultitenantPodNetworkConfigSpec defines the desired state of PodNetworkConfig | ||
| type MultitenantPodNetworkConfigSpec struct { | ||
| // name of PNI object from requesting cx pod | ||
| PodNetworkInstance string `json:"podNetworkInstance,omitempty"` | ||
| // name of the requesting cx pod | ||
| PodName string `json:"podName,omitempty"` | ||
| } | ||
|
|
||
| // MultitenantPodNetworkConfigStatus defines the observed state of PodNetworkConfig | ||
| type MultitenantPodNetworkConfigStatus struct { | ||
| // network container id | ||
| NCID string `json:"ncID,omitempty"` | ||
| // ip allocated to the network container | ||
| PrimaryIP string `json:"primaryIP,omitempty"` | ||
thatmattlong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // maps to the NIC to be injected for the network container | ||
| MacAddress string `json:"macAddress,omitempty"` | ||
| // Gateway IP | ||
| GatewayIP string `json:"gatewayIP,omitempty"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&MultitenantPodNetworkConfig{}, &MultitenantPodNetworkConfigList{}) | ||
| } | ||
99 changes: 99 additions & 0 deletions
99
crd/multitenantpodnetworkconfig/api/v1alpha1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package multitenantpodnetworkconfig | ||
|
|
||
| import ( | ||
| "context" | ||
| "reflect" | ||
|
|
||
| "github.com/Azure/azure-container-networking/crd" | ||
| "github.com/Azure/azure-container-networking/crd/multitenantpodnetworkconfig/api/v1alpha1" | ||
| "github.com/pkg/errors" | ||
| v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| typedv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| "k8s.io/client-go/rest" | ||
| ) | ||
|
|
||
| // Scheme is a runtime scheme containing the client-go scheme and the MultitenantPodNetworkConfig scheme. | ||
| var Scheme = runtime.NewScheme() | ||
|
|
||
| func init() { | ||
| _ = scheme.AddToScheme(Scheme) | ||
| _ = v1alpha1.AddToScheme(Scheme) | ||
| } | ||
|
|
||
| // Installer provides methods to manage the lifecycle of the MultitenantPodNetworkConfig resource definition. | ||
| type Installer struct { | ||
| cli typedv1.CustomResourceDefinitionInterface | ||
| } | ||
|
|
||
| func NewInstaller(c *rest.Config) (*Installer, error) { | ||
| cli, err := crd.NewCRDClientFromConfig(c) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to init crd client") | ||
| } | ||
| return &Installer{ | ||
| cli: cli, | ||
| }, nil | ||
| } | ||
|
|
||
| func (i *Installer) create(ctx context.Context, res *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { | ||
| res, err := i.cli.Create(ctx, res, metav1.CreateOptions{}) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to create mtpnc crd") | ||
| } | ||
| return res, nil | ||
| } | ||
|
|
||
| // Installs the embedded MultitenantPodNetworkConfig CRD definition in the cluster. | ||
| func (i *Installer) Install(ctx context.Context) (*v1.CustomResourceDefinition, error) { | ||
| mtpnc, err := GetMultitenantPodNetworkConfigs() | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to get embedded mtpnc crd") | ||
| } | ||
| return i.create(ctx, mtpnc) | ||
| } | ||
|
|
||
| // InstallOrUpdate installs the embedded MultitenantPodNetworkConfig CRD definition in the cluster or updates it if present. | ||
| func (i *Installer) InstallOrUpdate(ctx context.Context) (*v1.CustomResourceDefinition, error) { | ||
| mtpnc, err := GetMultitenantPodNetworkConfigs() | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to get embedded mtpnc crd") | ||
| } | ||
| current, err := i.create(ctx, mtpnc) | ||
| if !apierrors.IsAlreadyExists(err) { | ||
| return current, err | ||
| } | ||
| if current == nil { | ||
| current, err = i.cli.Get(ctx, mtpnc.Name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to get existing mtpnc crd") | ||
| } | ||
| } | ||
| if !reflect.DeepEqual(mtpnc.Spec.Versions, current.Spec.Versions) { | ||
| mtpnc.SetResourceVersion(current.GetResourceVersion()) | ||
| previous := *current | ||
| current, err = i.cli.Update(ctx, mtpnc, metav1.UpdateOptions{}) | ||
| if err != nil { | ||
| return &previous, errors.Wrap(err, "failed to update existing mtpnc crd") | ||
| } | ||
| } | ||
| return current, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package multitenantpodnetworkconfig | ||
|
|
||
| import ( | ||
| _ "embed" | ||
|
|
||
| "github.com/pkg/errors" | ||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
||
| // MultitenantPodNetworkConfigsYAML embeds the CRD YAML for downstream consumers. | ||
| // | ||
| //go:embed manifests/acn.azure.com_multitenantpodnetworkconfigs.yaml | ||
| var MultitenantPodNetworkConfigsYAML []byte | ||
|
|
||
| // GetMultitenantPodNetworkConfigs parses the raw []byte MultitenantPodNetworkConfigs in | ||
| // to a CustomResourceDefinition and returns it or an unmarshalling error. | ||
| func GetMultitenantPodNetworkConfigs() (*apiextensionsv1.CustomResourceDefinition, error) { | ||
| multitenantPodNetworkConfigs := &apiextensionsv1.CustomResourceDefinition{} | ||
| if err := yaml.Unmarshal(MultitenantPodNetworkConfigsYAML, &multitenantPodNetworkConfigs); err != nil { | ||
| return nil, errors.Wrap(err, "error unmarshalling embedded mtpnc") | ||
| } | ||
| return multitenantPodNetworkConfigs, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package multitenantpodnetworkconfig | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| const filename = "manifests/acn.azure.com_multitenantpodnetworkconfigs.yaml" | ||
|
|
||
| func TestEmbed(t *testing.T) { | ||
| b, err := os.ReadFile(filename) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, b, MultitenantPodNetworkConfigsYAML) | ||
| } | ||
|
|
||
| func TestGetMultitenantPodNetworkConfigs(t *testing.T) { | ||
| _, err := GetMultitenantPodNetworkConfigs() | ||
| assert.NoError(t, err) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.