Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connectivity: don't configure pod port information when unused #2194

Merged
merged 1 commit into from
Jan 9, 2024
Merged
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
53 changes: 30 additions & 23 deletions connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,37 @@ type deploymentParameters struct {
TerminationGracePeriodSeconds *int64
}

func (p *deploymentParameters) namedPort() string {
if len(p.NamedPort) == 0 {
return fmt.Sprintf("port-%d", p.Port)
}
return p.NamedPort
}

func (p *deploymentParameters) ports() (ports []corev1.ContainerPort) {
if p.Port != 0 {
ports = append(ports, corev1.ContainerPort{
Name: p.namedPort(), ContainerPort: int32(p.Port), HostPort: int32(p.HostPort)})
}

return ports
}

func (p *deploymentParameters) envs() (envs []corev1.EnvVar) {
if p.Port != 0 {
envs = append(envs,
corev1.EnvVar{Name: "PORT", Value: fmt.Sprintf("%d", p.Port)},
corev1.EnvVar{Name: "NAMED_PORT", Value: p.namedPort()},
)
}

return envs
}

func newDeployment(p deploymentParameters) *appsv1.Deployment {
if p.Replicas == 0 {
p.Replicas = 1
}
if len(p.NamedPort) == 0 {
p.NamedPort = fmt.Sprintf("port-%d", p.Port)
}
replicas32 := int32(p.Replicas)
dep := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -118,14 +142,9 @@ func newDeployment(p deploymentParameters) *appsv1.Deployment {
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: p.Name,
Env: []corev1.EnvVar{
{Name: "PORT", Value: fmt.Sprintf("%d", p.Port)},
{Name: "NAMED_PORT", Value: p.NamedPort},
},
Ports: []corev1.ContainerPort{
{Name: p.NamedPort, ContainerPort: int32(p.Port), HostPort: int32(p.HostPort)},
},
Name: p.Name,
Env: p.envs(),
Ports: p.ports(),
Image: p.Image,
ImagePullPolicy: corev1.PullIfNotPresent,
Command: p.Command,
Expand Down Expand Up @@ -213,7 +232,6 @@ type daemonSetParameters struct {
Kind string
Image string
Replicas int
Port int
Command []string
Affinity *corev1.Affinity
ReadinessProbe *corev1.Probe
Expand Down Expand Up @@ -472,7 +490,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
Image: "quay.io/cilium/test-connection-disruption:v0.0.13",
Replicas: 5,
Labels: map[string]string{"app": "test-conn-disrupt-client"},
Port: 8000,
Command: []string{
"tcd-client",
"--dispatch-interval", strconv.Itoa(int(ct.params.ConnDisruptDispatchInterval.Milliseconds())),
Expand Down Expand Up @@ -598,8 +615,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
clientDeployment := newDeployment(deploymentParameters{
Name: clientDeploymentName,
Kind: kindClientName,
NamedPort: "http-8080",
Port: 8080,
Image: ct.params.CurlImage,
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
Annotations: ct.params.DeploymentAnnotations.Match(clientDeploymentName),
Expand All @@ -622,8 +637,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
clientDeployment := newDeployment(deploymentParameters{
Name: client2DeploymentName,
Kind: kindClientName,
NamedPort: "http-8080",
Port: 8080,
Image: ct.params.CurlImage,
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
Labels: map[string]string{"other": "client"},
Expand Down Expand Up @@ -662,8 +675,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
clientDeployment := newDeployment(deploymentParameters{
Name: client3DeploymentName,
Kind: kindClientName,
NamedPort: "http-8080",
Port: 8080,
Image: ct.params.CurlImage,
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
Labels: map[string]string{"other": "client-other-node"},
Expand Down Expand Up @@ -701,8 +712,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
clientDeployment := newDeployment(deploymentParameters{
Name: clientCPDeployment,
Kind: kindClientName,
NamedPort: "http-8080",
Port: 8080,
Image: ct.params.CurlImage,
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
Labels: map[string]string{"other": "client"},
Expand Down Expand Up @@ -792,7 +801,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
Name: hostNetNSDeploymentName,
Kind: kindHostNetNS,
Image: ct.params.CurlImage,
Port: 8080,
Labels: map[string]string{"other": "host-netns"},
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
HostNetwork: true,
Expand All @@ -811,7 +819,6 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
Name: hostNetNSDeploymentNameNonCilium,
Kind: kindHostNetNS,
Image: ct.params.CurlImage,
Port: 8080,
Labels: map[string]string{"other": "host-netns"},
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
HostNetwork: true,
Expand Down