diff --git a/cns/service/main.go b/cns/service/main.go index 19b614d928..e22f4d5bc5 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -742,6 +742,7 @@ func main() { func InitializeMultiTenantController(ctx context.Context, httpRestService cns.HTTPService, cnsconfig configuration.CNSConfig) error { var multiTenantController multitenantcontroller.RequestController kubeConfig, err := ctrl.GetConfig() + kubeConfig.UserAgent = fmt.Sprintf("azure-cns-%s", version) if err != nil { return err } @@ -888,6 +889,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn httpRestServiceImplementation.SetNodeOrchestrator(&orchestrator) kubeConfig, err := ctrl.GetConfig() + kubeConfig.UserAgent = fmt.Sprintf("azure-cns-%s", version) if err != nil { logger.Errorf("[Azure CNS] Failed to get kubeconfig for request controller: %v", err) return err diff --git a/crd/nodenetworkconfig/Makefile b/crd/nodenetworkconfig/Makefile index 09d0569c10..a0ad0b4c31 100644 --- a/crd/nodenetworkconfig/Makefile +++ b/crd/nodenetworkconfig/Makefile @@ -14,7 +14,7 @@ generate: $(CONTROLLER_GEN) manifests: $(CONTROLLER_GEN) mkdir -p manifests - $(CONTROLLER_GEN) crd:trivialVersions=true paths="./..." output:crd:artifacts:config=manifests/ + $(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=manifests/ $(CONTROLLER_GEN): @make -C $(REPO_ROOT) $(CONTROLLER_GEN) diff --git a/crd/nodenetworkconfig/api/v1alpha/zz_generated.deepcopy.go b/crd/nodenetworkconfig/api/v1alpha/zz_generated.deepcopy.go index 87befcde00..54efa43e69 100644 --- a/crd/nodenetworkconfig/api/v1alpha/zz_generated.deepcopy.go +++ b/crd/nodenetworkconfig/api/v1alpha/zz_generated.deepcopy.go @@ -159,4 +159,4 @@ func (in *Scaler) DeepCopy() *Scaler { out := new(Scaler) in.DeepCopyInto(out) return out -} +} diff --git a/crd/nodenetworkconfig/client.go b/crd/nodenetworkconfig/client.go index 35488b68d2..031919ee26 100644 --- a/crd/nodenetworkconfig/client.go +++ b/crd/nodenetworkconfig/client.go @@ -2,7 +2,6 @@ package nodenetworkconfig import ( "context" - "fmt" "reflect" "github.com/Azure/azure-container-networking/crd" @@ -105,23 +104,12 @@ func (c *Client) InstallOrUpdate(ctx context.Context) (*v1.CustomResourceDefinit } // PatchSpec performs a server-side patch of the passed NodeNetworkConfigSpec to the NodeNetworkConfig specified by the NamespacedName. -func (c *Client) PatchSpec(ctx context.Context, key types.NamespacedName, spec *v1alpha.NodeNetworkConfigSpec) (*v1alpha.NodeNetworkConfig, error) { - obj := &v1alpha.NodeNetworkConfig{ - ObjectMeta: metav1.ObjectMeta{ - Name: key.Name, - Namespace: key.Namespace, - }, - } - - patch, err := specToJSON(spec) - if err != nil { - return nil, err - } - - if err := c.nnccli.Patch(ctx, obj, ctrlcli.RawPatch(types.ApplyPatchType, patch)); err != nil { +func (c *Client) PatchSpec(ctx context.Context, key types.NamespacedName, spec *v1alpha.NodeNetworkConfigSpec, fieldManager string) (*v1alpha.NodeNetworkConfig, error) { + obj := genPatchSkel(key) + obj.Spec = *spec + if err := c.nnccli.Patch(ctx, obj, ctrlcli.Apply, ctrlcli.ForceOwnership, ctrlcli.FieldOwner(fieldManager)); err != nil { return nil, errors.Wrap(err, "failed to patch nnc") } - return obj, nil } @@ -140,15 +128,26 @@ func (c *Client) UpdateSpec(ctx context.Context, key types.NamespacedName, spec } // SetOwnerRef sets the owner of the NodeNetworkConfig to the given object, using HTTP Patch -func (c *Client) SetOwnerRef(ctx context.Context, nnc *v1alpha.NodeNetworkConfig, owner metav1.Object) (*v1alpha.NodeNetworkConfig, error) { - newNNC := nnc.DeepCopy() - if err := ctrlutil.SetControllerReference(owner, newNNC, Scheme); err != nil { - return nil, fmt.Errorf("could not set controller reference for NNC %s/%s: %w", nnc.Namespace, nnc.Name, err) +func (c *Client) SetOwnerRef(ctx context.Context, key types.NamespacedName, owner metav1.Object, fieldManager string) (*v1alpha.NodeNetworkConfig, error) { + obj := genPatchSkel(key) + if err := ctrlutil.SetControllerReference(owner, obj, Scheme); err != nil { + return nil, errors.Wrapf(err, "failed to set controller reference for nnc") } - - if err := c.nnccli.Patch(ctx, newNNC, ctrlcli.MergeFrom(nnc)); err != nil { - return nil, fmt.Errorf("could not patch NNC %s/%s: %w", nnc.Namespace, nnc.Name, err) + if err := c.nnccli.Patch(ctx, obj, ctrlcli.Apply, ctrlcli.ForceOwnership, ctrlcli.FieldOwner(fieldManager)); err != nil { + return nil, errors.Wrapf(err, "failed to patch nnc") } + return obj, nil +} - return newNNC, nil +func genPatchSkel(key types.NamespacedName) *v1alpha.NodeNetworkConfig { + return &v1alpha.NodeNetworkConfig{ + TypeMeta: metav1.TypeMeta{ + APIVersion: v1alpha.GroupVersion.String(), + Kind: "NodeNetworkConfig", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: key.Name, + Namespace: key.Namespace, + }, + } } diff --git a/crd/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml b/crd/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml index 17d8c61857..a83ac1b8db 100644 --- a/crd/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml +++ b/crd/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.6.2 + controller-gen.kubebuilder.io/version: v0.7.0 creationTimestamp: null name: nodenetworkconfigs.acn.azure.com spec: diff --git a/hack/swift/Makefile b/hack/swift/Makefile index cc788cdda6..90fa1e58d3 100644 --- a/hack/swift/Makefile +++ b/hack/swift/Makefile @@ -23,6 +23,9 @@ help: ## Display this help ##@ Utilities +azlogin: + @$(AZCLI) login + azcfg: @$(AZCLI) account set -s $(SUB) @$(AZCLI) group create --location $(REGION) --name $(GROUP)