Skip to content

Commit

Permalink
add schdule limit for ip retained vm pod
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyasdf committed Aug 5, 2022
1 parent 1648abb commit 8e3cfa7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/hybridnet/templates/deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec:
command:
- /hybridnet/hybridnet-webhook
- --default-ip-retain={{ .Values.defaultIPRetain }}
- --feature-gates=MultiCluster={{ .Values.multiCluster }}
- --feature-gates=MultiCluster={{ .Values.multiCluster }},VMIPRetain={{ .Values.vmIPRetain }}
args:
- --port=9898
env:
Expand Down
3 changes: 3 additions & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"flag"
"os"

kubevirtv1 "kubevirt.io/api/core/v1"

"github.com/spf13/pflag"
admissionv1 "k8s.io/api/admission/v1"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
Expand Down Expand Up @@ -52,6 +54,7 @@ func init() {
_ = multiclusterv1.AddToScheme(scheme)
_ = admissionv1beta1.AddToScheme(scheme)
_ = admissionv1.AddToScheme(scheme)
_ = kubevirtv1.AddToScheme(scheme)
}

func main() {
Expand Down
31 changes: 31 additions & 0 deletions pkg/webhook/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

networkingv1 "github.com/alibaba/hybridnet/pkg/apis/networking/v1"
"github.com/alibaba/hybridnet/pkg/constants"
"github.com/alibaba/hybridnet/pkg/feature"
"github.com/alibaba/hybridnet/pkg/ipam/strategy"
"github.com/alibaba/hybridnet/pkg/utils"
)
Expand Down Expand Up @@ -142,6 +143,36 @@ func ParseNetworkConfigOfPodByPriority(ctx context.Context, c client.Reader, pod
return
}

// ignore terminating ipInstance
for i := range ipList.Items {
if ipList.Items[i].DeletionTimestamp == nil {
networkNameStr = ipList.Items[i].Spec.Network
break
}
}
}
} else if feature.VMIPRetainEnabled() {
var isVMPod bool
var vmName string
isVMPod, vmName, _, err = strategy.OwnByVirtualMachine(ctx, pod, c)
if err != nil {
err = fmt.Errorf("unable to check if pod %v/%v is for VM: %v", pod.Namespace, pod.Name, err)
return
}

if isVMPod {
ipList := &networkingv1.IPInstanceList{}
if err = c.List(
ctx,
ipList,
client.InNamespace(pod.Namespace),
client.MatchingLabels{
constants.LabelVM: vmName,
}); err != nil {
err = fmt.Errorf("failed to list allocated ip instances for vm %v: %v", vmName, err)
return
}

// ignore terminating ipInstance
for i := range ipList.Items {
if ipList.Items[i].DeletionTimestamp == nil {
Expand Down

0 comments on commit 8e3cfa7

Please sign in to comment.