From cbc41a51b3a939d314bac706e36e68fcac716f81 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:35:55 +0000 Subject: [PATCH 01/18] add nodeinfo crd --- crd/nodeinfo/Makefile | 19 +++++ crd/nodeinfo/README.md | 6 ++ crd/nodeinfo/api/v1alpha/groupversion_info.go | 23 +++++ crd/nodeinfo/api/v1alpha/nodeinfo.go | 44 ++++++++++ .../api/v1alpha/zz_generated.deepcopy.go | 83 +++++++++++++++++++ .../manifests/acn.azure.com_nodeinfoes.yaml | 53 ++++++++++++ 6 files changed, 228 insertions(+) create mode 100644 crd/nodeinfo/Makefile create mode 100644 crd/nodeinfo/README.md create mode 100644 crd/nodeinfo/api/v1alpha/groupversion_info.go create mode 100644 crd/nodeinfo/api/v1alpha/nodeinfo.go create mode 100644 crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go create mode 100644 crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml diff --git a/crd/nodeinfo/Makefile b/crd/nodeinfo/Makefile new file mode 100644 index 0000000000..c1fd004a43 --- /dev/null +++ b/crd/nodeinfo/Makefile @@ -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) diff --git a/crd/nodeinfo/README.md b/crd/nodeinfo/README.md new file mode 100644 index 0000000000..fed19b9b36 --- /dev/null +++ b/crd/nodeinfo/README.md @@ -0,0 +1,6 @@ +# NodeInfo CRDs + +This CRD is added to enable SWIFT multitenancy – which will be watched and managed by the MT-DNC-RC controller. + + +NodeInfo objects are created by Swift CNS as part of the node registration flow, and is used to pass any metadata from the VM needed by DNC / DNC-RC. E.g.: the vmUniqueID for use in PubSub queries / checks. diff --git a/crd/nodeinfo/api/v1alpha/groupversion_info.go b/crd/nodeinfo/api/v1alpha/groupversion_info.go new file mode 100644 index 0000000000..ecf249a821 --- /dev/null +++ b/crd/nodeinfo/api/v1alpha/groupversion_info.go @@ -0,0 +1,23 @@ +//go:build !ignore_uncovered +// +build !ignore_uncovered + +// Package v1alpha contains API Schema definitions for the acn v1alpha API group +// +kubebuilder:object:generate=true +// +groupName=acn.azure.com +package v1alpha + +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: "v1alpha"} + + // 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 +) diff --git a/crd/nodeinfo/api/v1alpha/nodeinfo.go b/crd/nodeinfo/api/v1alpha/nodeinfo.go new file mode 100644 index 0000000000..454ca0ce31 --- /dev/null +++ b/crd/nodeinfo/api/v1alpha/nodeinfo.go @@ -0,0 +1,44 @@ +//go:build !ignore_uncovered +// +build !ignore_uncovered + +package v1alpha + +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 NodesInfo API +// +kubebuilder:resource:scope=Namespaced +// +kubebuilder:resource:shortName=ni +// +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=1,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:default=0 + // +kubebuilder:validation:Optional + VMUniqueID string `json:"vmUniqueID,omitempty"` +} + +func init() { + SchemeBuilder.Register(&NodeInfo{}, &NodeInfoList{}) +} diff --git a/crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go b/crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go new file mode 100644 index 0000000000..bf4a476efe --- /dev/null +++ b/crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go @@ -0,0 +1,83 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeInfo) DeepCopyInto(out *NodeInfo) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeInfo. +func (in *NodeInfo) DeepCopy() *NodeInfo { + if in == nil { + return nil + } + out := new(NodeInfo) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeInfo) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeInfoList) DeepCopyInto(out *NodeInfoList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NodeInfo, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeInfoList. +func (in *NodeInfoList) DeepCopy() *NodeInfoList { + if in == nil { + return nil + } + out := new(NodeInfoList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeInfoList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeInfoSpec) DeepCopyInto(out *NodeInfoSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeInfoSpec. +func (in *NodeInfoSpec) DeepCopy() *NodeInfoSpec { + if in == nil { + return nil + } + out := new(NodeInfoSpec) + in.DeepCopyInto(out) + return out +} diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml new file mode 100644 index 0000000000..d86589da1d --- /dev/null +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml @@ -0,0 +1,53 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: nodeinfoes.acn.azure.com +spec: + group: acn.azure.com + names: + kind: NodeInfo + listKind: NodeInfoList + plural: nodeinfoes + shortNames: + - ni + singular: nodeinfo + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.vmUniqueID + name: VMUniqueID + priority: 1 + type: string + name: v1alpha + schema: + openAPIV3Schema: + description: NodeInfo is the Schema for the NodesInfo 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: + default: 0 + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} From 48813f63730ea3417443e85a391cd79ade0be374 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:46:52 +0000 Subject: [PATCH 02/18] update manifest default value --- crd/nodeinfo/api/v1alpha/nodeinfo.go | 1 - crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/crd/nodeinfo/api/v1alpha/nodeinfo.go b/crd/nodeinfo/api/v1alpha/nodeinfo.go index 454ca0ce31..f2fe830a47 100644 --- a/crd/nodeinfo/api/v1alpha/nodeinfo.go +++ b/crd/nodeinfo/api/v1alpha/nodeinfo.go @@ -34,7 +34,6 @@ type NodeInfoList struct { // NodeInfoSpec defines the desired state of NodeInfo type NodeInfoSpec struct { - // +kubebuilder:default=0 // +kubebuilder:validation:Optional VMUniqueID string `json:"vmUniqueID,omitempty"` } diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml index d86589da1d..9cb2de9fb2 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml @@ -43,7 +43,6 @@ spec: description: NodeInfoSpec defines the desired state of NodeInfo properties: vmUniqueID: - default: 0 type: string type: object type: object From 61234f56b8f597939713a4186945db9ae675248d Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 21:39:57 +0000 Subject: [PATCH 03/18] address pr comments --- crd/nodeinfo/README.md | 3 +- .../groupversion_info.go | 4 +- .../api/{v1alpha => v1alpha1}/nodeinfo.go | 3 +- .../zz_generated.deepcopy.go | 2 +- crd/nodeinfo/client.go | 161 ++++++++++++++++++ crd/nodeinfo/embed.go | 24 +++ crd/nodeinfo/embed_test.go | 21 +++ ...foes.yaml => acn.azure.com_nodesinfo.yaml} | 8 +- 8 files changed, 215 insertions(+), 11 deletions(-) rename crd/nodeinfo/api/{v1alpha => v1alpha1}/groupversion_info.go (95%) rename crd/nodeinfo/api/{v1alpha => v1alpha1}/nodeinfo.go (95%) rename crd/nodeinfo/api/{v1alpha => v1alpha1}/zz_generated.deepcopy.go (99%) create mode 100644 crd/nodeinfo/client.go create mode 100644 crd/nodeinfo/embed.go create mode 100644 crd/nodeinfo/embed_test.go rename crd/nodeinfo/manifests/{acn.azure.com_nodeinfoes.yaml => acn.azure.com_nodesinfo.yaml} (94%) diff --git a/crd/nodeinfo/README.md b/crd/nodeinfo/README.md index fed19b9b36..b4c39e8fbf 100644 --- a/crd/nodeinfo/README.md +++ b/crd/nodeinfo/README.md @@ -2,5 +2,4 @@ This CRD is added to enable SWIFT multitenancy – which will be watched and managed by the MT-DNC-RC controller. - -NodeInfo objects are created by Swift CNS as part of the node registration flow, and is used to pass any metadata from the VM needed by DNC / DNC-RC. E.g.: the vmUniqueID for use in PubSub queries / checks. +NodeInfo objects are created by Swift CNS as part of the node registration flow, and is used to pass any metadata from the VM needed by DNC / DNC-RC. E.g.: vmUniqueID etc diff --git a/crd/nodeinfo/api/v1alpha/groupversion_info.go b/crd/nodeinfo/api/v1alpha1/groupversion_info.go similarity index 95% rename from crd/nodeinfo/api/v1alpha/groupversion_info.go rename to crd/nodeinfo/api/v1alpha1/groupversion_info.go index ecf249a821..e00e625a54 100644 --- a/crd/nodeinfo/api/v1alpha/groupversion_info.go +++ b/crd/nodeinfo/api/v1alpha1/groupversion_info.go @@ -4,7 +4,7 @@ // Package v1alpha contains API Schema definitions for the acn v1alpha API group // +kubebuilder:object:generate=true // +groupName=acn.azure.com -package v1alpha +package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime/schema" @@ -13,7 +13,7 @@ import ( var ( // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "acn.azure.com", Version: "v1alpha"} + 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} diff --git a/crd/nodeinfo/api/v1alpha/nodeinfo.go b/crd/nodeinfo/api/v1alpha1/nodeinfo.go similarity index 95% rename from crd/nodeinfo/api/v1alpha/nodeinfo.go rename to crd/nodeinfo/api/v1alpha1/nodeinfo.go index f2fe830a47..f5c33c6625 100644 --- a/crd/nodeinfo/api/v1alpha/nodeinfo.go +++ b/crd/nodeinfo/api/v1alpha1/nodeinfo.go @@ -1,7 +1,7 @@ //go:build !ignore_uncovered // +build !ignore_uncovered -package v1alpha +package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -14,6 +14,7 @@ import ( // NodeInfo is the Schema for the NodesInfo API // +kubebuilder:resource:scope=Namespaced // +kubebuilder:resource:shortName=ni +// +kubebuilder:resource:path=nodesinfo // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=1,JSONPath=`.spec.vmUniqueID` type NodeInfo struct { diff --git a/crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go b/crd/nodeinfo/api/v1alpha1/zz_generated.deepcopy.go similarity index 99% rename from crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go rename to crd/nodeinfo/api/v1alpha1/zz_generated.deepcopy.go index bf4a476efe..91563a78cb 100644 --- a/crd/nodeinfo/api/v1alpha/zz_generated.deepcopy.go +++ b/crd/nodeinfo/api/v1alpha1/zz_generated.deepcopy.go @@ -3,7 +3,7 @@ // Code generated by controller-gen. DO NOT EDIT. -package v1alpha +package v1alpha1 import ( runtime "k8s.io/apimachinery/pkg/runtime" diff --git a/crd/nodeinfo/client.go b/crd/nodeinfo/client.go new file mode 100644 index 0000000000..fd40509224 --- /dev/null +++ b/crd/nodeinfo/client.go @@ -0,0 +1,161 @@ +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/apimachinery/pkg/types" + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" +) + +// 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 := GetNodesInfo() + 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 := GetNodesInfo() + 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 +} + +// Client provides methods to interact with instances of the NodeInfo custom resource. +type Client struct { + cli client.Client +} + +// NewClient creates a new NodeInfo client around the passed ctrlcli.Client. +func NewClient(cli client.Client) *Client { + return &Client{ + cli: cli, + } +} + +// Get returns the NodeInfo identified by the NamespacedName. +func (c *Client) Get(ctx context.Context, key types.NamespacedName) (*v1alpha1.NodeInfo, error) { + nodeInfo := &v1alpha1.NodeInfo{} + err := c.cli.Get(ctx, key, nodeInfo) + return nodeInfo, errors.Wrapf(err, "failed to get nodeinfo %v", key) +} + +// PatchSpec performs a server-side patch of the passed NodeInfoSpec to the NodeInfo specified by the NamespacedName. +func (c *Client) PatchSpec(ctx context.Context, key types.NamespacedName, spec *v1alpha1.NodeInfoSpec, fieldManager string) (*v1alpha1.NodeInfo, error) { + obj := genPatchSkel(key) + obj.Spec = *spec + if err := c.cli.Patch(ctx, obj, client.Apply, client.ForceOwnership, client.FieldOwner(fieldManager)); err != nil { + return nil, errors.Wrap(err, "failed to patch nodeinfo") + } + return obj, nil +} + +// UpdateSpec does a fetch, deepcopy, and update of the NodeInfo with the passed spec. +// Deprecated: UpdateSpec is deprecated and usage should migrate to PatchSpec. +func (c *Client) UpdateSpec(ctx context.Context, key types.NamespacedName, spec *v1alpha1.NodeInfoSpec) (*v1alpha1.NodeInfo, error) { + nodeinfo, err := c.Get(ctx, key) + if err != nil { + return nil, errors.Wrap(err, "failed to get nodeinfo") + } + spec.DeepCopyInto(&nodeinfo.Spec) + if err := c.cli.Update(ctx, nodeinfo); err != nil { + return nil, errors.Wrap(err, "failed to update nodeinfo") + } + return nodeinfo, nil +} + +// SetOwnerRef sets the controller of the NodeInfo to the given object atomically, using HTTP Patch. +// Deprecated: SetOwnerRef is deprecated, use the more correctly named SetControllerRef. +func (c *Client) SetOwnerRef(ctx context.Context, key types.NamespacedName, owner metav1.Object, fieldManager string) (*v1alpha1.NodeInfo, error) { + return c.SetControllerRef(ctx, key, owner, fieldManager) +} + +// SetControllerRef sets the controller of the NodeInfo to the given object atomically, using HTTP Patch. +func (c *Client) SetControllerRef(ctx context.Context, key types.NamespacedName, owner metav1.Object, fieldManager string) (*v1alpha1.NodeInfo, error) { + obj := genPatchSkel(key) + if err := ctrlutil.SetControllerReference(owner, obj, Scheme); err != nil { + return nil, errors.Wrapf(err, "failed to set controller reference for nodeinfo") + } + if err := c.cli.Patch(ctx, obj, client.Apply, client.ForceOwnership, client.FieldOwner(fieldManager)); err != nil { + return nil, errors.Wrapf(err, "failed to patch nodeinfo") + } + return obj, nil +} + +func genPatchSkel(key types.NamespacedName) *v1alpha1.NodeInfo { + return &v1alpha1.NodeInfo{ + TypeMeta: metav1.TypeMeta{ + APIVersion: v1alpha1.GroupVersion.String(), + Kind: "NodeInfo", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: key.Name, + Namespace: key.Namespace, + }, + } +} diff --git a/crd/nodeinfo/embed.go b/crd/nodeinfo/embed.go new file mode 100644 index 0000000000..b01ffba7ed --- /dev/null +++ b/crd/nodeinfo/embed.go @@ -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" +) + +// NodesInfoYAML embeds the CRD YAML for downstream consumers. +// +//go:embed manifests/acn.azure.com_nodesinfo.yaml +var NodesInfoYAML []byte + +// GetNodesInfoDefinition parses the raw []byte NodesInfo in +// to a CustomResourceDefinition and returns it or an unmarshalling error. +func GetNodesInfo() (*apiextensionsv1.CustomResourceDefinition, error) { + nodesInfo := &apiextensionsv1.CustomResourceDefinition{} + if err := yaml.Unmarshal(NodesInfoYAML, &nodesInfo); err != nil { + return nil, errors.Wrap(err, "error unmarshalling embedded nodeInfo") + } + return nodesInfo, nil +} diff --git a/crd/nodeinfo/embed_test.go b/crd/nodeinfo/embed_test.go new file mode 100644 index 0000000000..a90f71b9c6 --- /dev/null +++ b/crd/nodeinfo/embed_test.go @@ -0,0 +1,21 @@ +package nodeinfo + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +const filename = "manifests/acn.azure.com_nodesinfo.yaml" + +func TestEmbed(t *testing.T) { + b, err := os.ReadFile(filename) + assert.NoError(t, err) + assert.Equal(t, b, NodesInfoYAML) +} + +func TestGetNodesInfo(t *testing.T) { + _, err := GetNodesInfo() + assert.NoError(t, err) +} diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodesinfo.yaml similarity index 94% rename from crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml rename to crd/nodeinfo/manifests/acn.azure.com_nodesinfo.yaml index 9cb2de9fb2..20646ea36d 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodeinfoes.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodesinfo.yaml @@ -5,15 +5,13 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.3 creationTimestamp: null - name: nodeinfoes.acn.azure.com + name: nodesinfo.acn.azure.com spec: group: acn.azure.com names: kind: NodeInfo listKind: NodeInfoList - plural: nodeinfoes - shortNames: - - ni + plural: nodesinfo singular: nodeinfo scope: Namespaced versions: @@ -22,7 +20,7 @@ spec: name: VMUniqueID priority: 1 type: string - name: v1alpha + name: v1alpha1 schema: openAPIV3Schema: description: NodeInfo is the Schema for the NodesInfo API From 65c07a680c41e39b25e13a0328d873a1a3b10176 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 22:49:13 +0000 Subject: [PATCH 04/18] update readme --- crd/nodeinfo/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crd/nodeinfo/README.md b/crd/nodeinfo/README.md index b4c39e8fbf..34d6e16827 100644 --- a/crd/nodeinfo/README.md +++ b/crd/nodeinfo/README.md @@ -1,5 +1,5 @@ # NodeInfo CRDs -This CRD is added to enable SWIFT multitenancy – which will be watched and managed by the MT-DNC-RC controller. +This CRD is added to enable VNET multitenancy – which will be watched and managed by the control plane. -NodeInfo objects are created by Swift CNS as part of the node registration flow, and is used to pass any metadata from the VM needed by DNC / DNC-RC. E.g.: vmUniqueID etc +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 From ce0e2218a149a0dd8efcbbdf9ce653110a4556ea Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 22:59:31 +0000 Subject: [PATCH 05/18] update nodesInfo to nodeInfo --- crd/nodeinfo/api/v1alpha1/nodeinfo.go | 4 ++-- crd/nodeinfo/client.go | 4 ++-- crd/nodeinfo/embed.go | 16 ++++++++-------- crd/nodeinfo/embed_test.go | 8 ++++---- ...odesinfo.yaml => acn.azure.com_nodeinfo.yaml} | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) rename crd/nodeinfo/manifests/{acn.azure.com_nodesinfo.yaml => acn.azure.com_nodeinfo.yaml} (93%) diff --git a/crd/nodeinfo/api/v1alpha1/nodeinfo.go b/crd/nodeinfo/api/v1alpha1/nodeinfo.go index f5c33c6625..b0904dc79a 100644 --- a/crd/nodeinfo/api/v1alpha1/nodeinfo.go +++ b/crd/nodeinfo/api/v1alpha1/nodeinfo.go @@ -11,10 +11,10 @@ import ( // +kubebuilder:object:root=true -// NodeInfo is the Schema for the NodesInfo API +// NodeInfo is the Schema for the NodeInfo API // +kubebuilder:resource:scope=Namespaced // +kubebuilder:resource:shortName=ni -// +kubebuilder:resource:path=nodesinfo +// +kubebuilder:resource:path=nodeinfo // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=1,JSONPath=`.spec.vmUniqueID` type NodeInfo struct { diff --git a/crd/nodeinfo/client.go b/crd/nodeinfo/client.go index fd40509224..f61ca69c08 100644 --- a/crd/nodeinfo/client.go +++ b/crd/nodeinfo/client.go @@ -52,7 +52,7 @@ func (i *Installer) create(ctx context.Context, res *v1.CustomResourceDefinition // Install installs the embedded NodeInfo CRD definition in the cluster. func (i *Installer) Install(ctx context.Context) (*v1.CustomResourceDefinition, error) { - nodeinfo, err := GetNodesInfo() + nodeinfo, err := GetNodeInfo() if err != nil { return nil, errors.Wrap(err, "failed to get embedded nodeinfo crd") } @@ -61,7 +61,7 @@ func (i *Installer) Install(ctx context.Context) (*v1.CustomResourceDefinition, // 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 := GetNodesInfo() + nodeinfo, err := GetNodeInfo() if err != nil { return nil, errors.Wrap(err, "failed to get embedded nodeinfo crd") } diff --git a/crd/nodeinfo/embed.go b/crd/nodeinfo/embed.go index b01ffba7ed..190dc6ee81 100644 --- a/crd/nodeinfo/embed.go +++ b/crd/nodeinfo/embed.go @@ -8,17 +8,17 @@ import ( "sigs.k8s.io/yaml" ) -// NodesInfoYAML embeds the CRD YAML for downstream consumers. +// NodeInfoYAML embeds the CRD YAML for downstream consumers. // -//go:embed manifests/acn.azure.com_nodesinfo.yaml -var NodesInfoYAML []byte +//go:embed manifests/acn.azure.com_nodeinfo.yaml +var NodeInfoYAML []byte -// GetNodesInfoDefinition parses the raw []byte NodesInfo in +// GetNodeInfoDefinition parses the raw []byte NodeInfo in // to a CustomResourceDefinition and returns it or an unmarshalling error. -func GetNodesInfo() (*apiextensionsv1.CustomResourceDefinition, error) { - nodesInfo := &apiextensionsv1.CustomResourceDefinition{} - if err := yaml.Unmarshal(NodesInfoYAML, &nodesInfo); err != nil { +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 nodesInfo, nil + return nodeInfo, nil } diff --git a/crd/nodeinfo/embed_test.go b/crd/nodeinfo/embed_test.go index a90f71b9c6..ed42924962 100644 --- a/crd/nodeinfo/embed_test.go +++ b/crd/nodeinfo/embed_test.go @@ -7,15 +7,15 @@ import ( "github.com/stretchr/testify/assert" ) -const filename = "manifests/acn.azure.com_nodesinfo.yaml" +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, NodesInfoYAML) + assert.Equal(t, b, NodeInfoYAML) } -func TestGetNodesInfo(t *testing.T) { - _, err := GetNodesInfo() +func TestGetNodeInfo(t *testing.T) { + _, err := GetNodeInfo() assert.NoError(t, err) } diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodesinfo.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml similarity index 93% rename from crd/nodeinfo/manifests/acn.azure.com_nodesinfo.yaml rename to crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml index 20646ea36d..b9204305ba 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodesinfo.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml @@ -5,13 +5,13 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.3 creationTimestamp: null - name: nodesinfo.acn.azure.com + name: nodeinfo.acn.azure.com spec: group: acn.azure.com names: kind: NodeInfo listKind: NodeInfoList - plural: nodesinfo + plural: nodeinfo singular: nodeinfo scope: Namespaced versions: @@ -23,7 +23,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: NodeInfo is the Schema for the NodesInfo API + description: NodeInfo is the Schema for the NodeInfo API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation From b2f8a43f6dc63550b03fdeac40dc1b03119ccac9 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:43:34 +0000 Subject: [PATCH 06/18] add crd to crdgen check file --- .github/workflows/crdgen.yaml | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/crdgen.yaml b/.github/workflows/crdgen.yaml index 8b9a0190fc..fca426b249 100644 --- a/.github/workflows/crdgen.yaml +++ b/.github/workflows/crdgen.yaml @@ -3,28 +3,30 @@ on: workflow_dispatch: pull_request: types: - - opened - - reopened - - synchronize - - ready_for_review + - opened + - reopened + - synchronize + - ready_for_review jobs: crdgen119: strategy: matrix: - go-version: ['1.20'] + go-version: ["1.20"] os: [ubuntu-latest] name: CRDs are Generated runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - name: Regenerate NodeNetworkConfig CRD - run: make -C crd/nodenetworkconfig - - name: Regenerate MultitenantNetworkContainer CRD - run: make -C crd/multitenantnetworkcontainer - - name: Fail if the tree is dirty - run: test -z "$(git status --porcelain)" + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Regenerate NodeNetworkConfig CRD + run: make -C crd/nodenetworkconfig + - name: Regenerate MultitenantNetworkContainer CRD + run: make -C crd/multitenantnetworkcontainer + - name: Regenerate NodeInfo CRD + run: make -C crd/nodeinfo + - name: Fail if the tree is dirty + run: test -z "$(git status --porcelain)" From cc4e6ab2da90382078dda5eb27d487f4cab41a3a Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:55:26 +0000 Subject: [PATCH 07/18] update manifest file --- .../manifests/acn.azure.com_nodeinfo.yaml | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml index b9204305ba..2b87980650 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.11.3 - creationTimestamp: null + controller-gen.kubebuilder.io/version: v0.12.0 name: nodeinfo.acn.azure.com spec: group: acn.azure.com @@ -15,36 +14,38 @@ spec: singular: nodeinfo scope: Namespaced versions: - - additionalPrinterColumns: - - jsonPath: .spec.vmUniqueID - name: VMUniqueID - priority: 1 - 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: - status: {} + - additionalPrinterColumns: + - jsonPath: .spec.vmUniqueID + name: VMUniqueID + priority: 1 + 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: + status: {} From 8b0e7e81032a081e346fbd97f7c6e1e8efb92e06 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:18:07 +0000 Subject: [PATCH 08/18] remove whitespaces from manifest --- .../manifests/acn.azure.com_nodeinfo.yaml | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml index 2b87980650..6c2d1e2169 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml @@ -14,38 +14,36 @@ spec: singular: nodeinfo scope: Namespaced versions: - - additionalPrinterColumns: - - jsonPath: .spec.vmUniqueID - name: VMUniqueID - priority: 1 - 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: - status: {} + - additionalPrinterColumns: + - jsonPath: .spec.vmUniqueID + name: VMUniqueID + priority: 1 + 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: + status: {} From 32f8f1c2dc09720c5f69bdbf842ba6ef893e1641 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:40:02 +0000 Subject: [PATCH 09/18] remove whitespaces from crdgen --- .github/workflows/crdgen.yaml | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/crdgen.yaml b/.github/workflows/crdgen.yaml index fca426b249..3ce68c6dcc 100644 --- a/.github/workflows/crdgen.yaml +++ b/.github/workflows/crdgen.yaml @@ -3,30 +3,30 @@ on: workflow_dispatch: pull_request: types: - - opened - - reopened - - synchronize - - ready_for_review + - opened + - reopened + - synchronize + - ready_for_review jobs: crdgen119: strategy: matrix: - go-version: ["1.20"] + go-version: ['1.20'] os: [ubuntu-latest] name: CRDs are Generated runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - name: Regenerate NodeNetworkConfig CRD - run: make -C crd/nodenetworkconfig - - name: Regenerate MultitenantNetworkContainer CRD - run: make -C crd/multitenantnetworkcontainer - - name: Regenerate NodeInfo CRD - run: make -C crd/nodeinfo - - name: Fail if the tree is dirty - run: test -z "$(git status --porcelain)" + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Regenerate NodeNetworkConfig CRD + run: make -C crd/nodenetworkconfig + - name: Regenerate MultitenantNetworkContainer CRD + run: make -C crd/multitenantnetworkcontainer + - name: Regenerate NodeInfo CRD + run: make -C crd/nodeinfo + - name: Fail if the tree is dirty + run: test -z "$(git status --porcelain)" From 3b664ef251c9513523612c019c34a90c1aefd4e0 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:43:23 +0000 Subject: [PATCH 10/18] remove unnecessary helper funcs from CRD client --- crd/nodeinfo/client.go | 56 ------------------------------------------ 1 file changed, 56 deletions(-) diff --git a/crd/nodeinfo/client.go b/crd/nodeinfo/client.go index f61ca69c08..c0b6d221b0 100644 --- a/crd/nodeinfo/client.go +++ b/crd/nodeinfo/client.go @@ -16,7 +16,6 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" - ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) // Scheme is a runtime scheme containing the client-go scheme and the NodeInfo scheme. @@ -104,58 +103,3 @@ func (c *Client) Get(ctx context.Context, key types.NamespacedName) (*v1alpha1.N err := c.cli.Get(ctx, key, nodeInfo) return nodeInfo, errors.Wrapf(err, "failed to get nodeinfo %v", key) } - -// PatchSpec performs a server-side patch of the passed NodeInfoSpec to the NodeInfo specified by the NamespacedName. -func (c *Client) PatchSpec(ctx context.Context, key types.NamespacedName, spec *v1alpha1.NodeInfoSpec, fieldManager string) (*v1alpha1.NodeInfo, error) { - obj := genPatchSkel(key) - obj.Spec = *spec - if err := c.cli.Patch(ctx, obj, client.Apply, client.ForceOwnership, client.FieldOwner(fieldManager)); err != nil { - return nil, errors.Wrap(err, "failed to patch nodeinfo") - } - return obj, nil -} - -// UpdateSpec does a fetch, deepcopy, and update of the NodeInfo with the passed spec. -// Deprecated: UpdateSpec is deprecated and usage should migrate to PatchSpec. -func (c *Client) UpdateSpec(ctx context.Context, key types.NamespacedName, spec *v1alpha1.NodeInfoSpec) (*v1alpha1.NodeInfo, error) { - nodeinfo, err := c.Get(ctx, key) - if err != nil { - return nil, errors.Wrap(err, "failed to get nodeinfo") - } - spec.DeepCopyInto(&nodeinfo.Spec) - if err := c.cli.Update(ctx, nodeinfo); err != nil { - return nil, errors.Wrap(err, "failed to update nodeinfo") - } - return nodeinfo, nil -} - -// SetOwnerRef sets the controller of the NodeInfo to the given object atomically, using HTTP Patch. -// Deprecated: SetOwnerRef is deprecated, use the more correctly named SetControllerRef. -func (c *Client) SetOwnerRef(ctx context.Context, key types.NamespacedName, owner metav1.Object, fieldManager string) (*v1alpha1.NodeInfo, error) { - return c.SetControllerRef(ctx, key, owner, fieldManager) -} - -// SetControllerRef sets the controller of the NodeInfo to the given object atomically, using HTTP Patch. -func (c *Client) SetControllerRef(ctx context.Context, key types.NamespacedName, owner metav1.Object, fieldManager string) (*v1alpha1.NodeInfo, error) { - obj := genPatchSkel(key) - if err := ctrlutil.SetControllerReference(owner, obj, Scheme); err != nil { - return nil, errors.Wrapf(err, "failed to set controller reference for nodeinfo") - } - if err := c.cli.Patch(ctx, obj, client.Apply, client.ForceOwnership, client.FieldOwner(fieldManager)); err != nil { - return nil, errors.Wrapf(err, "failed to patch nodeinfo") - } - return obj, nil -} - -func genPatchSkel(key types.NamespacedName) *v1alpha1.NodeInfo { - return &v1alpha1.NodeInfo{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.GroupVersion.String(), - Kind: "NodeInfo", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: key.Name, - Namespace: key.Namespace, - }, - } -} From 51916b775f45655d025bf30a96368128b37c596b Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:58:14 +0000 Subject: [PATCH 11/18] address pr comments --- crd/nodeinfo/client.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/crd/nodeinfo/client.go b/crd/nodeinfo/client.go index c0b6d221b0..cb6314fc16 100644 --- a/crd/nodeinfo/client.go +++ b/crd/nodeinfo/client.go @@ -12,10 +12,8 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" ) // Scheme is a runtime scheme containing the client-go scheme and the NodeInfo scheme. @@ -84,22 +82,3 @@ func (i *Installer) InstallOrUpdate(ctx context.Context) (*v1.CustomResourceDefi } return current, nil } - -// Client provides methods to interact with instances of the NodeInfo custom resource. -type Client struct { - cli client.Client -} - -// NewClient creates a new NodeInfo client around the passed ctrlcli.Client. -func NewClient(cli client.Client) *Client { - return &Client{ - cli: cli, - } -} - -// Get returns the NodeInfo identified by the NamespacedName. -func (c *Client) Get(ctx context.Context, key types.NamespacedName) (*v1alpha1.NodeInfo, error) { - nodeInfo := &v1alpha1.NodeInfo{} - err := c.cli.Get(ctx, key, nodeInfo) - return nodeInfo, errors.Wrapf(err, "failed to get nodeinfo %v", key) -} From 2657290f635e547dbf4d3619fccebec5ae37129f Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 04:36:28 +0000 Subject: [PATCH 12/18] remove status subresource from nodeinfo crd --- crd/nodeinfo/api/v1alpha1/nodeinfo.go | 1 - 1 file changed, 1 deletion(-) diff --git a/crd/nodeinfo/api/v1alpha1/nodeinfo.go b/crd/nodeinfo/api/v1alpha1/nodeinfo.go index b0904dc79a..39b4c6f2b5 100644 --- a/crd/nodeinfo/api/v1alpha1/nodeinfo.go +++ b/crd/nodeinfo/api/v1alpha1/nodeinfo.go @@ -15,7 +15,6 @@ import ( // +kubebuilder:resource:scope=Namespaced // +kubebuilder:resource:shortName=ni // +kubebuilder:resource:path=nodeinfo -// +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=1,JSONPath=`.spec.vmUniqueID` type NodeInfo struct { metav1.TypeMeta `json:",inline"` From 418db482ec76384919756fde51b69f4dfc85a322 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 11:56:25 +0000 Subject: [PATCH 13/18] update manifest --- crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml index 6c2d1e2169..93b5fbcdde 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml @@ -45,5 +45,4 @@ spec: type: object served: true storage: true - subresources: - status: {} + subresources: {} From 68cce3aabeca3757b5b43edc96d01bfc8608589b Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 14:28:08 -0700 Subject: [PATCH 14/18] Update crd/nodeinfo/api/v1alpha1/nodeinfo.go Co-authored-by: Evan Baker --- crd/nodeinfo/api/v1alpha1/nodeinfo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crd/nodeinfo/api/v1alpha1/nodeinfo.go b/crd/nodeinfo/api/v1alpha1/nodeinfo.go index 39b4c6f2b5..58701fabf7 100644 --- a/crd/nodeinfo/api/v1alpha1/nodeinfo.go +++ b/crd/nodeinfo/api/v1alpha1/nodeinfo.go @@ -15,7 +15,7 @@ import ( // +kubebuilder:resource:scope=Namespaced // +kubebuilder:resource:shortName=ni // +kubebuilder:resource:path=nodeinfo -// +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=1,JSONPath=`.spec.vmUniqueID` +// +kubebuilder:printcolumn:name="VMUniqueID",type=string,priority=0,JSONPath=`.spec.vmUniqueID` type NodeInfo struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` From b3e0e05b8818a7e977b4d287b9274a0ee348b584 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 14:28:19 -0700 Subject: [PATCH 15/18] Update crd/nodeinfo/api/v1alpha1/groupversion_info.go Co-authored-by: Evan Baker --- crd/nodeinfo/api/v1alpha1/groupversion_info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crd/nodeinfo/api/v1alpha1/groupversion_info.go b/crd/nodeinfo/api/v1alpha1/groupversion_info.go index e00e625a54..88c30b03ed 100644 --- a/crd/nodeinfo/api/v1alpha1/groupversion_info.go +++ b/crd/nodeinfo/api/v1alpha1/groupversion_info.go @@ -1,7 +1,7 @@ //go:build !ignore_uncovered // +build !ignore_uncovered -// Package v1alpha contains API Schema definitions for the acn v1alpha API group +// Package v1alpha1 contains API Schema definitions for the acn v1alpha1 API group // +kubebuilder:object:generate=true // +groupName=acn.azure.com package v1alpha1 From d37ce113777de0f6526e4be32bdbb47b5534f924 Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 14:28:48 -0700 Subject: [PATCH 16/18] Update crd/nodeinfo/embed.go Co-authored-by: Evan Baker --- crd/nodeinfo/embed.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crd/nodeinfo/embed.go b/crd/nodeinfo/embed.go index 190dc6ee81..259602bb57 100644 --- a/crd/nodeinfo/embed.go +++ b/crd/nodeinfo/embed.go @@ -13,7 +13,7 @@ import ( //go:embed manifests/acn.azure.com_nodeinfo.yaml var NodeInfoYAML []byte -// GetNodeInfoDefinition parses the raw []byte NodeInfo in +// 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{} From 228cc092ffb7497f69ac2c77a6d2fed9c5085bbf Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Thu, 10 Aug 2023 21:52:34 +0000 Subject: [PATCH 17/18] add doc.go --- crd/nodeinfo/manifests/doc.go | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 crd/nodeinfo/manifests/doc.go diff --git a/crd/nodeinfo/manifests/doc.go b/crd/nodeinfo/manifests/doc.go new file mode 100644 index 0000000000..b08acc397f --- /dev/null +++ b/crd/nodeinfo/manifests/doc.go @@ -0,0 +1,3 @@ +// Package manifests exists to allow the rendered CRD manifests to be +// packaged in to dependent components. +package manifests From 65464a1ce7bffd42b8cc752819ee956f0da4296a Mon Sep 17 00:00:00 2001 From: aggarwal0009 <127549148+aggarwal0009@users.noreply.github.com> Date: Fri, 11 Aug 2023 00:18:08 +0000 Subject: [PATCH 18/18] update manifest --- crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml index 93b5fbcdde..9718299055 100644 --- a/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml +++ b/crd/nodeinfo/manifests/acn.azure.com_nodeinfo.yaml @@ -17,7 +17,6 @@ spec: - additionalPrinterColumns: - jsonPath: .spec.vmUniqueID name: VMUniqueID - priority: 1 type: string name: v1alpha1 schema: