Skip to content

Commit

Permalink
fixup: support image pull secret
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Jun 3, 2024
1 parent c915e78 commit de4b05c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 29 deletions.
5 changes: 2 additions & 3 deletions chart/open-feature-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
## @section Global
## @param defaultNamespace To override the namespace use the `--namespace` flag. This default is provided to ensure that the kustomize build charts in `/templates` deploy correctly when no `namespace` is provided via the `-n` flag.
defaultNamespace: open-feature-operator-system

# -- Secrets with credentials to pull images from a private registry. Registry secret names as an array.
imagePullSecrets: []
## @param imagePullSecret Secret containing credentials for images pulled by the operator (flagdProxyConfiguration.image, flagdConfiguration.image, controllerManager.manager.image, controllerManager.kubeRbacProxy.image).
imagePullSecret: ""

## @section Sidecar configuration
sidecarConfiguration:
Expand Down
7 changes: 6 additions & 1 deletion common/flagdproxy/flagdproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ type FlagdProxyConfiguration struct {
Tag string
Namespace string
OperatorDeploymentName string
ImagePullSecret string
}

func NewFlagdProxyConfiguration(env types.EnvConfig) *FlagdProxyConfiguration {
func NewFlagdProxyConfiguration(env types.EnvConfig, imagePullSecret string) *FlagdProxyConfiguration {
return &FlagdProxyConfiguration{
Image: env.FlagdProxyImage,
Tag: env.FlagdProxyTag,
Expand All @@ -49,6 +50,7 @@ func NewFlagdProxyConfiguration(env types.EnvConfig) *FlagdProxyConfiguration {
Port: env.FlagdProxyPort,
ManagementPort: env.FlagdProxyManagementPort,
DebugLogging: env.FlagdProxyDebugLogging,
ImagePullSecret: imagePullSecret,
}
}

Expand Down Expand Up @@ -172,6 +174,9 @@ func (f *FlagdProxyHandler) newFlagdProxyManifest(ownerReference *metav1.OwnerRe
},
Spec: corev1.PodSpec{
ServiceAccountName: FlagdProxyServiceAccountName,
ImagePullSecrets: []corev1.LocalObjectReference{
{Name: f.config.ImagePullSecret},
},
Containers: []corev1.Container{
{
Image: fmt.Sprintf("%s:%s", f.config.Image, f.config.Tag),
Expand Down
24 changes: 16 additions & 8 deletions common/flagdproxy/flagdproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

const pullSecret = "test-pullSecret"

func TestNewFlagdProxyConfiguration(t *testing.T) {

kpConfig := NewFlagdProxyConfiguration(types.EnvConfig{
FlagdProxyPort: 8015,
FlagdProxyManagementPort: 8016,
})
}, pullSecret)

require.NotNil(t, kpConfig)
require.Equal(t, &FlagdProxyConfiguration{
Port: 8015,
ManagementPort: 8016,
DebugLogging: false,
OperatorDeploymentName: common.OperatorDeploymentName,
ImagePullSecret: pullSecret,
}, kpConfig)
}

Expand All @@ -44,7 +48,7 @@ func TestNewFlagdProxyConfiguration_OverrideEnvVars(t *testing.T) {
FlagdProxyDebugLogging: true,
}

kpConfig := NewFlagdProxyConfiguration(env)
kpConfig := NewFlagdProxyConfiguration(env, pullSecret)

require.NotNil(t, kpConfig)
require.Equal(t, &FlagdProxyConfiguration{
Expand All @@ -55,11 +59,12 @@ func TestNewFlagdProxyConfiguration_OverrideEnvVars(t *testing.T) {
Tag: "my-tag",
Namespace: "my-namespace",
OperatorDeploymentName: common.OperatorDeploymentName,
ImagePullSecret: pullSecret,
}, kpConfig)
}

func TestNewFlagdProxyHandler(t *testing.T) {
kpConfig := NewFlagdProxyConfiguration(types.EnvConfig{})
kpConfig := NewFlagdProxyConfiguration(types.EnvConfig{}, pullSecret)

require.NotNil(t, kpConfig)

Expand Down Expand Up @@ -95,7 +100,7 @@ func TestDoesFlagdProxyExist(t *testing.T) {
},
}

kpConfig := NewFlagdProxyConfiguration(env)
kpConfig := NewFlagdProxyConfiguration(env, pullSecret)

require.NotNil(t, kpConfig)

Expand Down Expand Up @@ -123,7 +128,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_ProxyExistsWithBadVersion(t *testing
env := types.EnvConfig{
PodNamespace: "ns",
}
kpConfig := NewFlagdProxyConfiguration(env)
kpConfig := NewFlagdProxyConfiguration(env, pullSecret)

require.NotNil(t, kpConfig)

Expand Down Expand Up @@ -182,7 +187,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_ProxyExistsWithoutLabel(t *testing.T
env := types.EnvConfig{
PodNamespace: "ns",
}
kpConfig := NewFlagdProxyConfiguration(env)
kpConfig := NewFlagdProxyConfiguration(env, pullSecret)

require.NotNil(t, kpConfig)

Expand Down Expand Up @@ -231,7 +236,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_ProxyExistsWithNewestVersion(t *test
env := types.EnvConfig{
PodNamespace: "ns",
}
kpConfig := NewFlagdProxyConfiguration(env)
kpConfig := NewFlagdProxyConfiguration(env, pullSecret)

require.NotNil(t, kpConfig)

Expand Down Expand Up @@ -275,7 +280,7 @@ func TestFlagdProxyHandler_HandleFlagdProxy_CreateProxy(t *testing.T) {
FlagdProxyManagementPort: 90,
FlagdProxyDebugLogging: true,
}
kpConfig := NewFlagdProxyConfiguration(env)
kpConfig := NewFlagdProxyConfiguration(env, pullSecret)

require.NotNil(t, kpConfig)

Expand Down Expand Up @@ -356,6 +361,9 @@ func TestFlagdProxyHandler_HandleFlagdProxy_CreateProxy(t *testing.T) {
},
Spec: corev1.PodSpec{
ServiceAccountName: FlagdProxyServiceAccountName,
ImagePullSecrets: []corev1.LocalObjectReference{
{Name: pullSecret},
},
Containers: []corev1.Container{
{
Image: "image:tag",
Expand Down
5 changes: 2 additions & 3 deletions config/overlays/helm/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ spec:
replicas: 0{{ .Values.controllerManager.replicas }}
template:
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: "{{ .Values.imagePullSecret }}"
containers:
- name: manager
image: "{{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag }}"
Expand Down Expand Up @@ -94,6 +92,7 @@ spec:
- --sidecar-ram-limit={{ .Values.sidecarConfiguration.resources.limits.memory }}
- --sidecar-cpu-request={{ .Values.sidecarConfiguration.resources.requests.cpu }}
- --sidecar-ram-request={{ .Values.sidecarConfiguration.resources.requests.memory }}
- --image-pull-secret={{ .Values.imagePullSecret }}
- name: kube-rbac-proxy
image: "{{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag }}"
resources:
Expand Down
3 changes: 2 additions & 1 deletion controllers/core/featureflagsource/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestFeatureFlagSourceReconciler_Reconcile(t *testing.T) {
testNamespace = "test-namespace"
fsConfigName = "test-config"
deploymentName = "test-deploy"
pullSecret = "test-pullsecret"
)

tests := []struct {
Expand Down Expand Up @@ -92,7 +93,7 @@ func TestFeatureFlagSourceReconciler_Reconcile(t *testing.T) {
kpConfig := flagdproxy.NewFlagdProxyConfiguration(commontypes.EnvConfig{
FlagdProxyImage: "ghcr.io/open-feature/flagd-proxy",
FlagdProxyTag: flagdProxyTag,
})
}, pullSecret)

kpConfig.Namespace = testNamespace
kph := flagdproxy.NewFlagdProxyHandler(
Expand Down
15 changes: 8 additions & 7 deletions controllers/core/flagd/common/common.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package resources

type FlagdConfiguration struct {
FlagdPort int
OFREPPort int
SyncPort int
ManagementPort int
DebugLogging bool
Image string
Tag string
FlagdPort int
OFREPPort int
SyncPort int
ManagementPort int
DebugLogging bool
Image string
Tag string
ImagePullSecret string

OperatorNamespace string
OperatorDeploymentName string
Expand Down
5 changes: 3 additions & 2 deletions controllers/core/flagd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package flagd
import (
"github.com/open-feature/open-feature-operator/common"
"github.com/open-feature/open-feature-operator/common/types"
"github.com/open-feature/open-feature-operator/controllers/core/flagd/common"
resources "github.com/open-feature/open-feature-operator/controllers/core/flagd/common"
)

func NewFlagdConfiguration(env types.EnvConfig) resources.FlagdConfiguration {
func NewFlagdConfiguration(env types.EnvConfig, imagePullSecret string) resources.FlagdConfiguration {
return resources.FlagdConfiguration{
Image: env.FlagdImage,
Tag: env.FlagdTag,
Expand All @@ -16,5 +16,6 @@ func NewFlagdConfiguration(env types.EnvConfig) resources.FlagdConfiguration {
SyncPort: env.FlagdSyncPort,
ManagementPort: env.FlagdManagementPort,
DebugLogging: env.FlagdDebugLogging,
ImagePullSecret: imagePullSecret,
}
}
8 changes: 6 additions & 2 deletions controllers/core/flagd/resources/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
api "github.com/open-feature/open-feature-operator/apis/core/v1beta1"
"github.com/open-feature/open-feature-operator/common"
"github.com/open-feature/open-feature-operator/common/flagdinjector"
"github.com/open-feature/open-feature-operator/controllers/core/flagd/common"
resources "github.com/open-feature/open-feature-operator/controllers/core/flagd/common"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -95,7 +95,11 @@ func (r *FlagdDeployment) GetResource(ctx context.Context, flagd *api.Flagd) (cl
}

// override settings for the injected container for flagd standalone deployment mode

deployment.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
{
Name: r.FlagdConfig.ImagePullSecret,
},
}
deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", r.FlagdConfig.Image, r.FlagdConfig.Tag)

deployment.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{
Expand Down
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const (
sidecarRamLimitDefault = "64M"
sidecarCpuRequestDefault = "0.2"
sidecarRamRequestDefault = "32M"
imagePullSecretFlagName = "image-pull-secret"
imagePullSecretDefault = ""
)

var (
Expand All @@ -75,6 +77,7 @@ var (
probeAddr string
verbose bool
sidecarCpuLimit, sidecarRamLimit, sidecarCpuRequest, sidecarRamRequest string
imagePullSecret string
)

func init() {
Expand Down Expand Up @@ -103,6 +106,8 @@ func main() {
flag.StringVar(&sidecarCpuRequest, sidecarCpuRequestFlagName, sidecarCpuRequestDefault, "sidecar CPU minimum, in cores. (500m = .5 cores)")
flag.StringVar(&sidecarRamRequest, sidecarRamRequestFlagName, sidecarRamRequestDefault, "sidecar memory minimum, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)")

flag.StringVar(&imagePullSecret, imagePullSecretFlagName, imagePullSecretDefault, "secret containing credentials to pull images.")

flag.Parse()

level := zapcore.InfoLevel
Expand Down Expand Up @@ -178,7 +183,7 @@ func main() {
}

kph := flagdproxy.NewFlagdProxyHandler(
flagdproxy.NewFlagdProxyConfiguration(env),
flagdproxy.NewFlagdProxyConfiguration(env, imagePullSecret),
mgr.GetClient(),
ctrl.Log.WithName("FeatureFlagSource FlagdProxyHandler"),
)
Expand Down Expand Up @@ -210,7 +215,7 @@ func main() {
Scheme: mgr.GetScheme(),
Log: flagdControllerLogger,
}
flagdConfig := flagd.NewFlagdConfiguration(env)
flagdConfig := flagd.NewFlagdConfiguration(env, imagePullSecret)

if err = (&flagd.FlagdReconciler{
Client: mgr.GetClient(),
Expand Down

0 comments on commit de4b05c

Please sign in to comment.