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

feat: add flagd sidecar resources attribute #514

Merged
merged 1 commit into from
Aug 7, 2023
Merged
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
4 changes: 4 additions & 0 deletions apis/core/v1alpha1/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ type FlagSourceConfigurationSpec struct {
// OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
// +optional
OtelCollectorUri string `json:"otelCollectorUri"`

// Resources defines flagd sidecar resources. Default to operator sidecar-cpu-* and sidecar-ram-* flags.
// +optional
Resources corev1.ResourceRequirements `json:"resources"`
L3o-pold marked this conversation as resolved.
Show resolved Hide resolved
}

type Source struct {
Expand Down
1 change: 1 addition & 0 deletions apis/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apis/core/v1alpha2/featureflagconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type FeatureFlagConfigurationSpec struct {
FlagDSpec *FlagDSpec `json:"flagDSpec"`
// FeatureFlagSpec is the structured representation of the feature flag specification
FeatureFlagSpec FeatureFlagSpec `json:"featureFlagSpec,omitempty"`
// Resources defines flagd sidecar resources. Default to operator sidecar-cpu-* and sidecar-ram-* flags.
// +optional
Resources corev1.ResourceRequirements `json:"resources"`
}

type FlagDSpec struct {
Expand Down
1 change: 1 addition & 0 deletions apis/core/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apis/core/v1alpha3/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ type FlagSourceConfigurationSpec struct {
// OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
// +optional
OtelCollectorUri string `json:"otelCollectorUri"`

// Resources defines flagd sidecar resources. Default to operator sidecar-cpu-* and sidecar-ram-* flags.
// +optional
Resources corev1.ResourceRequirements `json:"resources"`
}

type Source struct {
Expand Down
1 change: 1 addition & 0 deletions apis/core/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chart/open-feature-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ The command removes all the Kubernetes components associated with the chart and
| `sidecarConfiguration.probesEnabled` | Enable or Disable Liveness and Readiness probes of the flagd sidecar. When enabled, HTTP probes( paths - `/readyz`, `/healthz`) are set with an initial delay of 5 seconds. | `true` |
| `sidecarConfiguration.debugLogging` | Controls the addition of the `--debug` flag to the container startup arguments. | `false` |
| `sidecarConfiguration.otelCollectorUri` | Otel exporter uri. | `""` |
| `sidecarConfiguration.resources` | Override resources of the flagd sidecar. | `{}` |

### Flagd-proxy configuration

Expand Down
2 changes: 2 additions & 0 deletions chart/open-feature-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ sidecarConfiguration:
debugLogging: false
## @param sidecarConfiguration.otelCollectorUri Otel exporter uri.
otelCollectorUri: ""
## @param sidecarConfiguration.resources Override resources of the flagd sidecar.
resources: { }

## @section Flagd-proxy configuration
flagdProxyConfiguration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,54 @@ spec:
description: ProbesEnabled defines whether to enable liveness and
readiness probes of flagd sidecar. Default true (enabled).
type: boolean
resources:
description: Resources defines flagd sidecar resources. Default to
operator sidecar-cpu-limit and sidecar-ram-limit flags.
properties:
claims:
description: "Claims lists the names of resources, defined in
spec.resourceClaims, that are used by this container. \n This
is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable. It can only be set
for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: Name must match the name of one entry in pod.spec.resourceClaims
of the Pod where this field is used. It makes that resource
available inside a container.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources
allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
rolloutOnChange:
description: RolloutOnChange dictates whether annotated deployments
will be restarted when configuration changes are detected in this
Expand Down
8 changes: 8 additions & 0 deletions controllers/common/flagd-injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ func (fi *FlagdContainerInjector) InjectFlagd(
)
}

if len(flagSourceConfig.Resources.Requests) != 0 {
flagdContainer.Resources.Requests = flagSourceConfig.Resources.Requests
}

if len(flagSourceConfig.Resources.Limits) != 0 {
flagdContainer.Resources.Limits = flagSourceConfig.Resources.Limits
}

addFlagdContainer(podSpec, flagdContainer)

return nil
Expand Down
50 changes: 50 additions & 0 deletions controllers/common/flagd-injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/open-feature/open-feature-operator/pkg/utils"
"github.com/stretchr/testify/require"
appsV1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -137,6 +138,55 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithOtelCollectorUri(t
require.Equal(t, expectedDeployment, deployment)
}

func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithResources(t *testing.T) {

namespace, fakeClient := initContainerInjectionTestEnv()

fi := &FlagdContainerInjector{
Client: fakeClient,
Logger: testr.New(t),
FlagdProxyConfig: getProxyConfig(),
FlagDResourceRequirements: getResourceRequirements(),
}

deployment := appsV1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "my-deployment",
Namespace: namespace,
},
Spec: appsV1.DeploymentSpec{},
}

flagSourceConfig := getFlagSourceConfigSpec()

flagSourceConfig.DefaultSyncProvider = v1alpha1.SyncProviderGrpc

flagSourceConfig.Resources = corev1.ResourceRequirements{
Limits: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: *resource.NewMilliQuantity(100, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(256*1<<20, resource.BinarySI),
},
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: *resource.NewMilliQuantity(100, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(256*1<<20, resource.BinarySI),
},
}

flagSourceConfig.Sources = []v1alpha1.Source{{}}

err := fi.InjectFlagd(context.Background(), &deployment.ObjectMeta, &deployment.Spec.Template.Spec, flagSourceConfig)
require.Nil(t, err)

expectedDeployment := getExpectedDeployment(namespace)

expectedDeployment.Annotations = nil

expectedDeployment.Spec.Template.Spec.Containers[0].Args = []string{"start", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]"}
expectedDeployment.Spec.Template.Spec.Containers[0].Resources = flagSourceConfig.Resources

require.Equal(t, expectedDeployment, deployment)
}

func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithSyncProviderArgs(t *testing.T) {

namespace, fakeClient := initContainerInjectionTestEnv()
Expand Down
77 changes: 77 additions & 0 deletions docs/crds.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,13 @@ FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration
ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled).<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#flagsourceconfigurationspecresources">resources</a></b></td>
<td>object</td>
<td>
Resources defines flagd sidecar resources. Default to operator sidecar-cpu-limit and sidecar-ram-limit flags.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>rolloutOnChange</b></td>
<td>boolean</td>
Expand Down Expand Up @@ -1079,6 +1086,76 @@ Selects a key of a secret in the pod's namespace
</tr></tbody>
</table>


### FlagSourceConfiguration.spec.resources
<sup><sup>[↩ Parent](#flagsourceconfigurationspec)</sup></sup>



Resources defines flagd sidecar resources. Default to operator sidecar-cpu-limit and sidecar-ram-limit flags.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#flagsourceconfigurationspecresourcesclaimsindex">claims</a></b></td>
<td>[]object</td>
<td>
Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.
This is an alpha field and requires enabling the DynamicResourceAllocation feature gate.
This field is immutable. It can only be set for containers.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>limits</b></td>
<td>map[string]int or string</td>
<td>
Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>requests</b></td>
<td>map[string]int or string</td>
<td>
Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### FlagSourceConfiguration.spec.resources.claims[index]
<sup><sup>[↩ Parent](#flagsourceconfigurationspecresources)</sup></sup>



ResourceClaim references one entry in PodSpec.ResourceClaims.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>name</b></td>
<td>string</td>
<td>
Name must match the name of one entry in pod.spec.resourceClaims of the Pod where this field is used. It makes that resource available inside a container.<br/>
</td>
<td>true</td>
</tr></tbody>
</table>

# core.openfeature.dev/v1alpha2

Resource Types:
Expand Down
28 changes: 18 additions & 10 deletions docs/flag_source_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ sources:
`FlagSourceConfiguration` further allows to provide configurations to the injected flagd sidecar.
Table given below is non-exhaustive list of overriding options,

| Configuration | Explanation | Default |
|------------------|-------------------------------|----------------------------|
| port | Flag evaluation endpoint port | 8013 |
| metricsPort | Metrics port | 8014 |
| evaluator | Evaluator to use | json |
| image | flagD image | ghcr.io/open-feature/flagd |
| tag | flagD image tag | Latest tag |
| probesEnabled | Enable/Disable health probes | true |
| otelCollectorUri | Otel exporter uri | |
| Configuration | Explanation | Default |
|------------------|-------------------------------|------------------------------------------------|
| port | Flag evaluation endpoint port | 8013 |
| metricsPort | Metrics port | 8014 |
| evaluator | Evaluator to use | json |
| image | flagD image | ghcr.io/open-feature/flagd |
| tag | flagD image tag | Latest tag |
| probesEnabled | Enable/Disable health probes | true |
| otelCollectorUri | Otel exporter uri | |
| resources | flagD resources | operator sidecar-cpu-* and sidecar-ram-* flags |

## Merging of configurations

Expand All @@ -118,7 +119,7 @@ metadata:
name: flag-source-sample
spec:
metricsPort: 8080
Port: 80
port: 80
evaluator: json
image: my-custom-sidecar-image
defaultSyncProvider: filepath
Expand All @@ -135,6 +136,13 @@ spec:
probesEnabled: true
debugLogging: false
otelCollectorUri: http://localhost:4317
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 200m
memory: 256Mi
```

The relevant `FlagSourceConfigurations` are passed to the operator by setting the `openfeature.dev/flagsourceconfiguration` annotation, and is responsible for providing the full configuration of the injected sidecar.
Expand Down
Loading