Skip to content

Commit cc11a56

Browse files
committed
set own kubeproxy
1 parent f585761 commit cc11a56

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

test/e2e/framework/azure/create-cilium-cluster.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"fmt"
77
"log"
88
"os"
9+
"os/exec"
10+
"path/filepath"
11+
"time"
912

1013
k8s "github.com/Azure/azure-container-networking/test/e2e/framework/kubernetes"
1114
"github.com/Azure/azure-container-networking/test/e2e/manifests"
@@ -22,6 +25,20 @@ var (
2225
ErrEmptyFile = fmt.Errorf("empty file")
2326
)
2427

28+
// local stand-ins for kube-proxy config (removed from armcontainerservice/v4)
29+
type ipvsConfig struct {
30+
Scheduler string `json:"scheduler,omitempty"`
31+
TCPTimeoutSeconds *int32 `json:"TCPTimeoutSeconds,omitempty"`
32+
TCPFinTimeoutSeconds *int32 `json:"TCPFINTimeoutSeconds,omitempty"`
33+
UDPTimeoutSeconds *int32 `json:"UDPTimeoutSeconds,omitempty"`
34+
}
35+
36+
type kubeProxyConfig struct {
37+
Enabled *bool `json:"enabled,omitempty"`
38+
Mode string `json:"mode,omitempty"` // e.g. "IPVS"
39+
IpvsConfig *ipvsConfig `json:"ipvsConfig,omitempty"`
40+
}
41+
2542
type CreateBYOCiliumCluster struct {
2643
SubscriptionID string
2744
ResourceGroupName string
@@ -83,6 +100,20 @@ func (c *CreateBYOCiliumCluster) Run() error {
83100
subnetkey := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", c.SubscriptionID, c.ResourceGroupName, c.VnetName, c.SubnetName)
84101
ciliumCluster.Properties.AgentPoolProfiles[0].VnetSubnetID = to.Ptr(subnetkey)
85102

103+
// Build (and log) kube-proxy config using local stand-in types
104+
kp := kubeProxyConfig{
105+
Enabled: to.Ptr(false),
106+
Mode: "IPVS",
107+
IpvsConfig: &ipvsConfig{
108+
Scheduler: "LeastConnection",
109+
TCPTimeoutSeconds: to.Ptr(int32(900)), // set by existing kube-proxy in hack/aks/kube-proxy.json
110+
TCPFinTimeoutSeconds: to.Ptr(int32(120)),
111+
UDPTimeoutSeconds: to.Ptr(int32(300)),
112+
},
113+
}
114+
log.Printf("using kube-proxy config:\n")
115+
printjson(kp)
116+
86117
// Deploy cluster
87118
cred, err := azidentity.NewAzureCLICredential(nil)
88119
if err != nil {
@@ -109,6 +140,11 @@ func (c *CreateBYOCiliumCluster) Run() error {
109140
return fmt.Errorf("failed to create cluster: %w", err)
110141
}
111142

143+
// After the cluster exists, apply kube-proxy config via CLI
144+
if err := applyKubeProxyConfigWithCLI(ctx, c.SubscriptionID, c.ResourceGroupName, c.ClusterName, kp); err != nil {
145+
return fmt.Errorf("failed to apply kube-proxy config: %w", err)
146+
}
147+
112148
// get kubeconfig
113149
log.Printf("getting kubeconfig for cluster \"%s\" in resource group \"%s\"...", c.ClusterName, c.ResourceGroupName)
114150
clientset, err := c.getKubeConfig()
@@ -197,3 +233,46 @@ func (c *CreateBYOCiliumCluster) deployCiliumComponents(clientset *kubernetes.Cl
197233

198234
return nil
199235
}
236+
237+
// applyKubeProxyConfigWithCLI writes the config to a temporary JSON file and runs:
238+
// az aks update -g <rg> -n <cluster> --subscription <sub> --kube-proxy-config <file>
239+
func applyKubeProxyConfigWithCLI(ctx context.Context, subscriptionID, rg, cluster string, kp kubeProxyConfig) error {
240+
dir, err := os.MkdirTemp("", "kube-proxy-config")
241+
if err != nil {
242+
return err
243+
}
244+
defer os.RemoveAll(dir)
245+
246+
fp := filepath.Join(dir, "kube-proxy.json")
247+
f, err := os.Create(fp)
248+
if err != nil {
249+
return err
250+
}
251+
enc := json.NewEncoder(f)
252+
enc.SetIndent("", " ")
253+
if err := enc.Encode(kp); err != nil {
254+
f.Close()
255+
return err
256+
}
257+
if err := f.Close(); err != nil {
258+
return err
259+
}
260+
261+
// ensure we have a reasonable timeout if caller didn't set a deadline
262+
if _, ok := ctx.Deadline(); !ok {
263+
var cancel context.CancelFunc
264+
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Minute)
265+
defer cancel()
266+
}
267+
268+
cmd := exec.CommandContext(ctx, "az", "aks", "update",
269+
"-g", rg,
270+
"-n", cluster,
271+
"--subscription", subscriptionID,
272+
"--kube-proxy-config", fp,
273+
"--only-show-errors",
274+
)
275+
cmd.Stdout = os.Stdout
276+
cmd.Stderr = os.Stderr
277+
return cmd.Run()
278+
}

0 commit comments

Comments
 (0)