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

fix: Add --port argument in flagd pods for set flagd service port #710

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions common/flagdinjector/flagdinjector.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ func (fi *FlagdContainerInjector) generateBasicFlagdContainer(flagSourceConfig *
"start",
"--management-port",
fmt.Sprintf("%d", flagSourceConfig.ManagementPort),
"--port",
fmt.Sprintf("%d", flagSourceConfig.Port),
},
ImagePullPolicy: common.FlagdImagePullPolicy,
VolumeMounts: []corev1.VolumeMount{},
Expand All @@ -403,6 +405,10 @@ func (fi *FlagdContainerInjector) generateBasicFlagdContainer(flagSourceConfig *
Name: "management",
ContainerPort: flagSourceConfig.ManagementPort,
},
{
Name: "flagd",
ContainerPort: flagSourceConfig.Port,
},
},
SecurityContext: getSecurityContext(),
Resources: fi.FlagdResourceRequirements,
Expand Down
28 changes: 16 additions & 12 deletions common/flagdinjector/flagdinjector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider(t *testing.T) {

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithDebugLogging(t *te

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--debug"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--debug"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithOtelCollectorUri(t

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--metrics-exporter", "otel", "--otel-collector-uri", "localhost:4317"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--metrics-exporter", "otel", "--otel-collector-uri", "localhost:4317"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithResources(t *testi

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]"}
expectedPod.Spec.Containers[1].Resources = flagSourceConfig.Resources

require.Equal(t, expectedPod, pod)
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithSyncProviderArgs(t

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--sync-provider-args", "arg-1", "--sync-provider-args", "arg-2"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--sync-provider-args", "arg-1", "--sync-provider-args", "arg-2"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestFlagdContainerInjector_InjectFlagdKubernetesSource(t *testing.T) {

expectedPod := getExpectedPod(namespace)

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"my-namespace/server-side\",\"provider\":\"kubernetes\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"my-namespace/server-side\",\"provider\":\"kubernetes\"}]"}

require.Equal(t, expectedPod, pod)

Expand Down Expand Up @@ -305,7 +305,7 @@ func TestFlagdContainerInjector_InjectFlagdFilePathSource(t *testing.T) {
},
}

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"/etc/flagd/my-namespace_server-side/my-namespace_server-side.flagd.json\",\"provider\":\"file\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"/etc/flagd/my-namespace_server-side/my-namespace_server-side.flagd.json\",\"provider\":\"file\"}]"}
expectedPod.Spec.Containers[1].VolumeMounts = []v1.VolumeMount{
{
Name: "server-side",
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestFlagdContainerInjector_InjectFlagdFilePathSource_UpdateReferencedConfig
},
}

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"/etc/flagd/my-namespace_server-side/my-namespace_server-side.flagd.json\",\"provider\":\"file\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"/etc/flagd/my-namespace_server-side/my-namespace_server-side.flagd.json\",\"provider\":\"file\"}]"}
expectedPod.Spec.Containers[1].VolumeMounts = []v1.VolumeMount{
{
Name: "server-side",
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestFlagdContainerInjector_InjectHttpSource(t *testing.T) {

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"http://localhost:8013\",\"provider\":\"http\",\"bearerToken\":\"my-token\",\"interval\":8}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"http://localhost:8013\",\"provider\":\"http\",\"bearerToken\":\"my-token\",\"interval\":8}]"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -482,7 +482,7 @@ func TestFlagdContainerInjector_InjectGrpcSource(t *testing.T) {

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"grpc://localhost:8013\",\"provider\":\"grpc\",\"certPath\":\"cert-path\",\"tls\":true,\"providerID\":\"provider-id\",\"selector\":\"selector\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"grpc://localhost:8013\",\"provider\":\"grpc\",\"certPath\":\"cert-path\",\"tls\":true,\"providerID\":\"provider-id\",\"selector\":\"selector\"}]"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestFlagdContainerInjector_InjectProxySource_ProxyIsReady(t *testing.T) {

expectedPod.Annotations = nil

expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--sources", "[{\"uri\":\"flagd-proxy-svc.my-namespace.svc.cluster.local:8013\",\"provider\":\"grpc\",\"selector\":\"core.openfeature.dev/my-namespace/\"}]"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013", "--sources", "[{\"uri\":\"flagd-proxy-svc.my-namespace.svc.cluster.local:8013\",\"provider\":\"grpc\",\"selector\":\"core.openfeature.dev/my-namespace/\"}]"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestFlagdContainerInjector_Inject_FlagdContainerAlreadyPresent(t *testing.T
expectedPod := getExpectedPod(namespace)

expectedPod.Annotations = nil
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014"}
expectedPod.Spec.Containers[1].Args = []string{"start", "--management-port", "8014", "--port", "8013"}

require.Equal(t, expectedPod, pod)
}
Expand Down Expand Up @@ -831,6 +831,10 @@ func getExpectedPod(namespace string) v1.Pod {
Name: "management",
ContainerPort: int32(8014),
},
{
Name: "flagd",
ContainerPort: int32(8013),
},
},
Env: []v1.EnvVar{
{
Expand Down
Loading