Skip to content

Commit

Permalink
WIP, POC: Use v1.multus-cni.io/default-network
Browse files Browse the repository at this point in the history
In order to specify ipam-claim-reference for the primary network

Signed-off-by: Or Shoval <[email protected]>
  • Loading branch information
oshoval committed Sep 18, 2024
1 parent 49ee8d7 commit b32aa9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const (
NetworkRolePrimary NetworkRole = "primary"
)

const OVNPrimaryNetworkIPAMClaimAnnotation = "k8s.ovn.org/primary-udn-ipamclaim"
const (
MultusDefaultNetwork = "v1.multus-cni.io/default-network"
DefaultNetworkName = "ovn-kubernetes"
)

type RelevantConfig struct {
Name string `json:"name"`
Expand Down
23 changes: 17 additions & 6 deletions pkg/ipamclaimswebhook/podmutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (a *IPAMClaimsValet) Handle(ctx context.Context, request admission.Request)
if newPod == nil {
newPod = pod.DeepCopy()
}
updatePodWithOVNPrimaryNetworkIPAMClaimAnnotation(newPod, newPrimaryNetworkIPAMClaimName)
updatePodWithDefaultNetworkAnnotation(a.Client, newPod, newPrimaryNetworkIPAMClaimName)
}

if newPod != nil {
Expand Down Expand Up @@ -159,8 +159,21 @@ func updatePodSelectionElements(pod *corev1.Pod, networks []*v1.NetworkSelection
return nil
}

func updatePodWithOVNPrimaryNetworkIPAMClaimAnnotation(pod *corev1.Pod, primaryNetworkIPAMClaimName string) {
pod.Annotations[config.OVNPrimaryNetworkIPAMClaimAnnotation] = primaryNetworkIPAMClaimName
func updatePodWithDefaultNetworkAnnotation(cli client.Client, pod *corev1.Pod, ipamClaimName string) error {
nadKey := types.NamespacedName{
Namespace: "default",
Name: config.DefaultNetworkName,
}

nad := v1.NetworkAttachmentDefinition{}
if err := cli.Get(context.Background(), nadKey, &nad); err != nil {
return err
}

pod.Annotations[config.MultusDefaultNetwork] =
fmt.Sprintf(`[{"namespace":"default","name":"%s","ipam-claim-reference":"%s"}]`, config.DefaultNetworkName, ipamClaimName)

return nil
}

func ensureIPAMClaimRefAtNetworkSelectionElements(ctx context.Context,
Expand Down Expand Up @@ -236,9 +249,7 @@ func ensureIPAMClaimRefAtNetworkSelectionElements(ctx context.Context,
func findNewPrimaryNetworkIPAMClaimName(ctx context.Context,
cli client.Client, pod *corev1.Pod, vmName string) (string, error) {
log := logf.FromContext(ctx)
if pod.Annotations[config.OVNPrimaryNetworkIPAMClaimAnnotation] != "" {
return "", nil
}

primaryNetworkNAD, err := udn.FindPrimaryNetwork(ctx, cli, pod.Namespace)
if err != nil {
return "", err
Expand Down

0 comments on commit b32aa9a

Please sign in to comment.