Skip to content

Commit

Permalink
enhance: Kubernetes-NodePort supports network disabled
Browse files Browse the repository at this point in the history
Signed-off-by: ChrisLiu <[email protected]>
  • Loading branch information
chrisliu1995 committed Jun 15, 2024
1 parent b6fdc23 commit 2cbd507
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cloudprovider/kubernetes/nodeport.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
NodePortNetwork = "Kubernetes-NodePort"

PortProtocolsConfigName = "PortProtocols"

SvcSelectorDisabledKey = "game.kruise.io/svc-selector-disabled"
)

type NodePortPlugin struct {
Expand Down Expand Up @@ -98,6 +100,24 @@ func (n *NodePortPlugin) OnPodUpdated(client client.Client, pod *corev1.Pod, ctx
return pod, cperrors.ToPluginError(client.Update(ctx, consNodePortSvc(npc, pod, client, ctx)), cperrors.ApiCallError)
}

// disable network
if networkManager.GetNetworkDisabled() && svc.Spec.Selector[SvcSelectorKey] == pod.GetName() {
newSelector := svc.Spec.Selector
newSelector[SvcSelectorDisabledKey] = pod.GetName()
delete(svc.Spec.Selector, SvcSelectorKey)
svc.Spec.Selector = newSelector
return pod, cperrors.ToPluginError(client.Update(ctx, svc), cperrors.ApiCallError)
}

// enable network
if !networkManager.GetNetworkDisabled() && svc.Spec.Selector[SvcSelectorDisabledKey] == pod.GetName() {
newSelector := svc.Spec.Selector
newSelector[SvcSelectorKey] = pod.GetName()
delete(svc.Spec.Selector, SvcSelectorDisabledKey)
svc.Spec.Selector = newSelector
return pod, cperrors.ToPluginError(client.Update(ctx, svc), cperrors.ApiCallError)
}

// allow not ready containers
if util.IsAllowNotReadyContainers(networkManager.GetNetworkConfig()) {
toUpDateSvc, err := utils.AllowNotReadyContainers(client, ctx, pod, svc, false)
Expand Down

0 comments on commit 2cbd507

Please sign in to comment.