Skip to content

Commit

Permalink
Deploy unleash-edge alongside local featureFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
ezr-ondrej committed Jan 3, 2025
1 parent 7bfc7f9 commit 1df3978
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 18 deletions.
3 changes: 2 additions & 1 deletion apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ type ObjectStoreConfig struct {
}

type FeatureFlagsImages struct {
Unleash string `json:"unleash,omitempty"`
Unleash string `json:"unleash,omitempty"`
UnleashEdge string `json:"unleashEdge,omitempty"`
}

// FeatureFlagsMode details the mode of operation of the Clowder FeatureFlags
Expand Down
21 changes: 11 additions & 10 deletions controllers/cloud.redhat.com/clowderconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (

type ClowderConfig struct {
Images struct {
MBOP string `json:"mbop"`
Caddy string `json:"caddy"`
CaddyGateway string `json:"caddyGateway"`
Keycloak string `json:"Keycloak"`
Mocktitlements string `json:"mocktitlements"`
CaddyReverseProxy string `json:"caddyReverseProxy"`
ObjectStoreMinio string `json:"objectStoreMinio"`
FeatureFlagsUnleash string `json:"featureFlagsUnleash"`
TokenRefresher string `json:"tokenRefresher"`
OtelCollector string `json:"otelCollector"`
MBOP string `json:"mbop"`
Caddy string `json:"caddy"`
CaddyGateway string `json:"caddyGateway"`
Keycloak string `json:"Keycloak"`
Mocktitlements string `json:"mocktitlements"`
CaddyReverseProxy string `json:"caddyReverseProxy"`
ObjectStoreMinio string `json:"objectStoreMinio"`
FeatureFlagsUnleash string `json:"featureFlagsUnleash"`
FeatureFlagsUnleashEdge string `json:"featureFlagsUnleashEdge"`
TokenRefresher string `json:"tokenRefresher"`
OtelCollector string `json:"otelCollector"`
} `json:"images"`
DebugOptions struct {
Logging struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,84 @@ func makeLocalFeatureFlags(o obj.ClowdObject, objMap providers.ObjectMap, _ bool
},
}

dd.Spec.Template.Spec.Containers = []core.Container{c}
dd.Spec.Template.SetLabels(labels)
portEdge := int32(3063)

envVarsEdge := []core.EnvVar{
{
// communication with the main featureflags service on localhost
Name: "UPSTREAM_URL",
Value: fmt.Sprintf("http://127.0.0.1:%d", port),
},
}
envVarsEdge = provutils.AppendEnvVarsFromSecret(envVarsEdge, nn.Name,
provutils.NewSecretEnvVar("TOKENS", "clientAccessToken"))

servicePorts := []core.ServicePort{{
Name: "featureflags",
Port: port,
Protocol: "TCP",
TargetPort: intstr.FromInt(int(port)),
portsEdge := []core.ContainerPort{{
Name: "service",
ContainerPort: portEdge,
Protocol: "TCP",
}}

readinessProbeEdge := core.Probe{
ProbeHandler: core.ProbeHandler{
Exec: &core.ExecAction{
Command: []string{"/unleash-edge", "ready"},
},
},
InitialDelaySeconds: 1,
TimeoutSeconds: 5,
PeriodSeconds: 30,
SuccessThreshold: 1,
FailureThreshold: 3,
}

livenessProbeEdge := core.Probe{
ProbeHandler: core.ProbeHandler{
Exec: &core.ExecAction{
Command: []string{"/unleash-edge", "health"},
},
},
InitialDelaySeconds: 30,
TimeoutSeconds: 5,
PeriodSeconds: 30,
SuccessThreshold: 1,
FailureThreshold: 3,
}

ce := core.Container{
Name: fmt.Sprint(nn.Name, "-edge"),
Image: GetFeatureFlagsUnleashEdgeImage(env),
Env: envVarsEdge,
Ports: portsEdge,
ReadinessProbe: &readinessProbeEdge,
LivenessProbe: &livenessProbeEdge,
ImagePullPolicy: core.PullIfNotPresent,
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
"memory": resource.MustParse("50Mi"),
"cpu": resource.MustParse("40m"),
},
},
}

dd.Spec.Template.Spec.Containers = []core.Container{c, ce}
dd.Spec.Template.SetLabels(labels)

servicePorts := []core.ServicePort{
{
Name: "featureflags",
Port: port,
Protocol: "TCP",
TargetPort: intstr.FromInt(int(port)),
},
{
Name: "featureflags-edge",
Port: portEdge,
Protocol: "TCP",
TargetPort: intstr.FromInt(int(portEdge)),
},
}

utils.MakeService(svc, nn, labels, servicePorts, o, nodePort)
return nil
}
11 changes: 11 additions & 0 deletions controllers/cloud.redhat.com/providers/featureflags/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var DefaultImageFeatureFlagsUnleash = "unleashorg/unleash-server:5.6.9"
var DefaultImageFeatureFlagsUnleashEdge = "unleashorg/unleash-edge:v19.6.3"

func GetFeatureFlagsUnleashImage(env *crd.ClowdEnvironment) string {
if env.Spec.Providers.FeatureFlags.Images.Unleash != "" {
Expand All @@ -21,6 +22,16 @@ func GetFeatureFlagsUnleashImage(env *crd.ClowdEnvironment) string {
return DefaultImageFeatureFlagsUnleash
}

func GetFeatureFlagsUnleashEdgeImage(env *crd.ClowdEnvironment) string {
if env.Spec.Providers.FeatureFlags.Images.UnleashEdge != "" {
return env.Spec.Providers.FeatureFlags.Images.UnleashEdge
}
if clowderconfig.LoadedConfig.Images.FeatureFlagsUnleashEdge != "" {
return clowderconfig.LoadedConfig.Images.FeatureFlagsUnleashEdge
}
return DefaultImageFeatureFlagsUnleashEdge
}

// ProvName identifies the featureflags provider.
var ProvName = "featureflags"

Expand Down

0 comments on commit 1df3978

Please sign in to comment.