Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crd/nodenetworkconfig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

47 changes: 23 additions & 24 deletions crd/nodenetworkconfig/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package nodenetworkconfig

import (
"context"
"fmt"
"reflect"

"github.com/Azure/azure-container-networking/crd"
Expand Down Expand Up @@ -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
}

Expand All @@ -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,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions hack/swift/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down