-
Notifications
You must be signed in to change notification settings - Fork 260
[Multitenancy]: Add NodeInfo crd #2113
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
19 commits
Select commit
Hold shift + click to select a range
cbc41a5
add nodeinfo crd
aggarwal0009 48813f6
update manifest default value
aggarwal0009 61234f5
address pr comments
aggarwal0009 65c07a6
update readme
aggarwal0009 ce0e221
update nodesInfo to nodeInfo
aggarwal0009 b2f8a43
add crd to crdgen check file
aggarwal0009 cc4e6ab
update manifest file
aggarwal0009 8b0e7e8
remove whitespaces from manifest
aggarwal0009 32f8f1c
remove whitespaces from crdgen
aggarwal0009 3b664ef
remove unnecessary helper funcs from CRD client
aggarwal0009 51916b7
address pr comments
aggarwal0009 2657290
remove status subresource from nodeinfo crd
aggarwal0009 418db48
update manifest
aggarwal0009 68cce3a
Update crd/nodeinfo/api/v1alpha1/nodeinfo.go
aggarwal0009 b3e0e05
Update crd/nodeinfo/api/v1alpha1/groupversion_info.go
aggarwal0009 d37ce11
Update crd/nodeinfo/embed.go
aggarwal0009 228cc09
add doc.go
aggarwal0009 65464a1
update manifest
aggarwal0009 fa2632e
Merge branch 'master' into ankaggar/NodeInfo-CRD
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,5 @@ | ||
| # NodeInfo CRDs | ||
|
|
||
| This CRD is added to enable VNET multitenancy – which will be watched and managed by the control plane. | ||
|
|
||
| NodeInfo objects are created by CNS as part of the node registration flow, and is used to pass any metadata from the VM needed by control plane. E.g.: vmUniqueID etc |
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 | ||
| ) |
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,43 @@ | ||
| //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 | ||
|
|
||
| // NodeInfo is the Schema for the NodeInfo API | ||
| // +kubebuilder:resource:scope=Namespaced | ||
| // +kubebuilder:resource:shortName=ni | ||
| // +kubebuilder:resource:path=nodeinfo | ||
| // +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=0,JSONPath=`.spec.vmUniqueID` | ||
| type NodeInfo struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec NodeInfoSpec `json:"spec,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // NodeInfoList contains a list of NodeInfo | ||
| type NodeInfoList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []NodeInfo `json:"items"` | ||
| } | ||
|
|
||
| // NodeInfoSpec defines the desired state of NodeInfo | ||
| type NodeInfoSpec struct { | ||
| // +kubebuilder:validation:Optional | ||
| VMUniqueID string `json:"vmUniqueID,omitempty"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&NodeInfo{}, &NodeInfoList{}) | ||
| } |
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 nodeinfo | ||
|
|
||
| import ( | ||
| "context" | ||
| "reflect" | ||
|
|
||
| "github.com/Azure/azure-container-networking/crd" | ||
| "github.com/Azure/azure-container-networking/crd/nodeinfo/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 NodeInfo scheme. | ||
| var Scheme = runtime.NewScheme() | ||
|
|
||
| func init() { | ||
| _ = scheme.AddToScheme(Scheme) | ||
| _ = v1alpha1.AddToScheme(Scheme) | ||
| } | ||
|
|
||
| // Installer provides methods to manage the lifecycle of the NodeInfo 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 nodeinfo crd") | ||
| } | ||
| return res, nil | ||
| } | ||
|
|
||
| // Install installs the embedded NodeInfo CRD definition in the cluster. | ||
| func (i *Installer) Install(ctx context.Context) (*v1.CustomResourceDefinition, error) { | ||
| nodeinfo, err := GetNodeInfo() | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to get embedded nodeinfo crd") | ||
| } | ||
| return i.create(ctx, nodeinfo) | ||
| } | ||
|
|
||
| // InstallOrUpdate installs the embedded NodeInfo CRD definition in the cluster or updates it if present. | ||
| func (i *Installer) InstallOrUpdate(ctx context.Context) (*v1.CustomResourceDefinition, error) { | ||
| nodeinfo, err := GetNodeInfo() | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to get embedded nodeinfo crd") | ||
| } | ||
| current, err := i.create(ctx, nodeinfo) | ||
| if !apierrors.IsAlreadyExists(err) { | ||
| return current, err | ||
| } | ||
| if current == nil { | ||
| current, err = i.cli.Get(ctx, nodeinfo.Name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to get existing nodeinfo crd") | ||
| } | ||
| } | ||
| if !reflect.DeepEqual(nodeinfo.Spec.Versions, current.Spec.Versions) { | ||
| nodeinfo.SetResourceVersion(current.GetResourceVersion()) | ||
| previous := *current | ||
| current, err = i.cli.Update(ctx, nodeinfo, metav1.UpdateOptions{}) | ||
| if err != nil { | ||
| return &previous, errors.Wrap(err, "failed to update existing nodeinfo 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 nodeinfo | ||
|
|
||
| import ( | ||
| _ "embed" | ||
|
|
||
| "github.com/pkg/errors" | ||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
||
| // NodeInfoYAML embeds the CRD YAML for downstream consumers. | ||
| // | ||
| //go:embed manifests/acn.azure.com_nodeinfo.yaml | ||
| var NodeInfoYAML []byte | ||
|
|
||
| // GetNodeInfo parses the raw []byte NodeInfo in | ||
| // to a CustomResourceDefinition and returns it or an unmarshalling error. | ||
| func GetNodeInfo() (*apiextensionsv1.CustomResourceDefinition, error) { | ||
| nodeInfo := &apiextensionsv1.CustomResourceDefinition{} | ||
| if err := yaml.Unmarshal(NodeInfoYAML, &nodeInfo); err != nil { | ||
| return nil, errors.Wrap(err, "error unmarshalling embedded nodeInfo") | ||
| } | ||
| return nodeInfo, 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 nodeinfo | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| const filename = "manifests/acn.azure.com_nodeinfo.yaml" | ||
|
|
||
| func TestEmbed(t *testing.T) { | ||
| b, err := os.ReadFile(filename) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, b, NodeInfoYAML) | ||
| } | ||
|
|
||
| func TestGetNodeInfo(t *testing.T) { | ||
| _, err := GetNodeInfo() | ||
| assert.NoError(t, err) | ||
| } |
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,47 @@ | ||
| --- | ||
| apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| metadata: | ||
| annotations: | ||
| controller-gen.kubebuilder.io/version: v0.12.0 | ||
| name: nodeinfo.acn.azure.com | ||
| spec: | ||
| group: acn.azure.com | ||
| names: | ||
| kind: NodeInfo | ||
| listKind: NodeInfoList | ||
| plural: nodeinfo | ||
| singular: nodeinfo | ||
| scope: Namespaced | ||
| versions: | ||
| - additionalPrinterColumns: | ||
| - jsonPath: .spec.vmUniqueID | ||
| name: VMUniqueID | ||
| type: string | ||
| name: v1alpha1 | ||
| schema: | ||
| openAPIV3Schema: | ||
| description: NodeInfo is the Schema for the NodeInfo API | ||
| 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: NodeInfoSpec defines the desired state of NodeInfo | ||
| properties: | ||
| vmUniqueID: | ||
| type: string | ||
| type: object | ||
| type: object | ||
| served: true | ||
| storage: true | ||
| subresources: {} | ||
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 @@ | ||
| // Package manifests exists to allow the rendered CRD manifests to be | ||
| // packaged in to dependent components. | ||
| package manifests |
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.