Skip to content
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
42 changes: 41 additions & 1 deletion .earthly/configuration/templates/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ spec:
stacks:
- '*'
key: opentelemetry.metrics.dsn
{{- if .Values.v2 }}
value: grpc://opentelemetry-collector.monitoring.svc.cluster.local:4317?insecure=true
{{- else }}
value: grpc://otel-collector-opentelemetry-collector.formance.svc.cluster.local:4317?insecure=true
{{- end }}
---
apiVersion: formance.com/v1beta1
kind: Settings
Expand All @@ -67,7 +71,11 @@ spec:
stacks:
- '*'
key: opentelemetry.traces.dsn
{{- if .Values.v2 }}
value: grpc://opentelemetry-collector.monitoring.svc.cluster.local:4317?insecure=true
{{- else }}
value: grpc://otel-collector-opentelemetry-collector.formance.svc.cluster.local:4317?insecure=true
{{- end }}
---
apiVersion: formance.com/v1beta1
kind: Settings
Expand Down Expand Up @@ -97,4 +105,36 @@ spec:
stacks:
- '*'
key: "modules.*.grace-period"
value: "5s"
value: "5s"
{{- if .Values.v2 }}
---
apiVersion: formance.com/v1beta1
kind: Settings
metadata:
name: rewrite-ghcr-registry
spec:
key: 'registries."ghcr.io".endpoint'
stacks:
- '*'
value: {{ .Values.ghcrRegistry }}?pullSecret=zot
---
apiVersion: formance.com/v1beta1
kind: Settings
metadata:
name: gateway-ingress-annotations
spec:
key: 'gateway.ingress.annotations'
stacks:
- '*'
value: 'cert-manager.io/cluster-issuer=zerossl'
---
apiVersion: formance.com/v1beta1
kind: Settings
metadata:
name: gateway-ingress-tls
spec:
key: 'gateway.ingress.tls.enabled'
stacks:
- '*'
value: 'true'
{{- end }}
27 changes: 22 additions & 5 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
VERSION 0.8

IMPORT github.com/formancehq/earthly:tags/v0.19.1 AS core
ARG core=github.com/formancehq/earthly:tags/v0.19.1
IMPORT $core AS core

FROM core+base-image

Expand Down Expand Up @@ -61,21 +62,37 @@ deploy:
# --wait \
# --create-namespace ./base
RUN helm dependency update ./operator
RUN --no-cache helm upgrade --install --namespace formance-system --install formance-operator \

ARG FORMANCE_DEV_CLUSTER_V2=no
LET ADDITIONAL_ARGS=""
IF [ "$FORMANCE_DEV_CLUSTER_V2" == "yes" ]
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set imagePullSecrets[0].name=zot"
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set image.repository=$REPOSITORY/formancehq/operator"
END

ARG --required REPOSITORY=
RUN --no-cache helm upgrade --install --namespace formance --install formance-operator \
--wait \
--debug \
--create-namespace \
--set image.tag=$tag \
--set operator.licence.token=$LICENCE_TOKEN \
--set operator.licence.issuer=$LICENCE_ISSUER ./operator \
--set operator.dev=true
--set operator.dev=true $ADDITIONAL_ARGS
WORKDIR /
COPY .earthly .earthly
WORKDIR .earthly
RUN kubectl get versions default || kubectl apply -f k8s-versions.yaml
ARG user

SET ADDITIONAL_ARGS=""
IF [ "$FORMANCE_DEV_CLUSTER_V2" == "yes" ]
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set v2=true"
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set ghcrRegistry=$REPOSITORY"
END
RUN --secret tld helm upgrade --install operator-configuration ./configuration \
--namespace formance-system \
--set gateway.fallback=https://console.$user.$tld
--namespace formance \
--set gateway.fallback=https://console.$user.$tld $ADDITIONAL_ARGS

deploy-staging:
FROM --pass-args core+base-argocd
Expand Down
3 changes: 2 additions & 1 deletion api/formance.com/v1beta1/benthos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type BenthosSpec struct {
//+optional
Batching *Batching `json:"batching,omitempty"`
//+optional
InitContainers []corev1.Container `json:"initContainers"`
InitContainers []corev1.Container `json:"initContainers"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}

type BenthosStatus struct {
Expand Down
12 changes: 7 additions & 5 deletions api/formance.com/v1beta1/stargate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ type StargateTLSConfig struct {
type StargateSpec struct {
ModuleProperties `json:",inline"`
StackDependency `json:",inline"`
ServerURL string `json:"serverURL"`
OrganizationID string `json:"organizationID"`
StackID string `json:"stackID"`
Auth StargateAuthSpec `json:"auth"`
TLS StargateTLSConfig `json:"tls"`
ServerURL string `json:"serverURL"`
OrganizationID string `json:"organizationID"`
StackID string `json:"stackID"`
Auth StargateAuthSpec `json:"auth"`

//+optional
TLS StargateTLSConfig `json:"tls"`
}

// StargateStatus defines the observed state of Stargate
Expand Down
5 changes: 5 additions & 0 deletions api/formance.com/v1beta1/zz_generated.deepcopy.go

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

15 changes: 15 additions & 0 deletions config/crd/bases/formance.com_benthos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ spec:
Allow to enable dev mode on the module
Dev mode is used to allow some application to do custom setup in development mode (allow insecure certificates for example)
type: boolean
imagePullSecrets:
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
initContainers:
items:
description: A single application container that you want to run
Expand Down
1 change: 0 additions & 1 deletion config/crd/bases/formance.com_stargates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ spec:
- organizationID
- serverURL
- stackID
- tls
type: object
status:
description: StargateStatus defines the observed state of Stargate
Expand Down
4 changes: 2 additions & 2 deletions docs/09-Configuration reference/01-Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ While we have some basic types (string, number, bool ...), we also have some com
## Available settings

| Key | Type | Example | Description |
|------------------------------------------------------------------------------------------|--------|---------------------------------------------------------| ------------------------------------------------------------------------------------------------------------------------------ |
|------------------------------------------------------------------------------------------|-------- |-----------------------------------------------------------| ------------------------------------------------------------------------------------------------------------------------------ |
| aws.service-account | string | | AWS Role |
| postgres.`<module-name>`.uri | URI | | Postgres database configuration |
| elasticsearch.dsn | URI | | Elasticsearch connection URI |
Expand Down Expand Up @@ -42,7 +42,7 @@ While we have some basic types (string, number, bool ...), we also have some com
| jobs.`<owner-kind>`.spec.template.annotations | Map | firstannotations=X, anotherannotations=Y | Configure the annotations on specific jobs'modules |
| jobs.`<owner-kind>`.init-containers.`<container-name>`.run-as | Map | user=X, group=X | Configure the security context for init containers in jobs by specifying the user and group IDs to run as |
| jobs.`<owner-kind>`.containers.`<container-name>`.run-as | Map | user=X, group=X | Configure the security context for containers in jobs by specifying the user and group IDs to run as |
| registries.`<name>`.endpoint | string | | Specify a custom endpoint for a specific docker repository |
| registries.`<name>`.endpoint | string | example.com?pullSecret=foo | Specify a custom endpoint for a specific docker repository |
| registries.`<name>`.images.`<path>`.rewrite | string | formancehq/example | Allow to rewrite the image path |
| search.batching | Map | period=1s, count=10 | Override default batching parameters |
| services.`<service-name>`.annotations | Map | | Allow to specify custom annotations to apply on created k8s services |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ Benthos is the Schema for the benthos API
| `resourceRequirements` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#resourcerequirements-v1-core)_ | | | |
| `batching` _[Batching](#batching)_ | | | |
| `initContainers` _[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#container-v1-core) array_ | | | |
| `imagePullSecrets` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#localobjectreference-v1-core) array_ | | | |

###### Batching

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -59,7 +59,6 @@ require (
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
go.uber.org/mock v0.5.0
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ spec:
Allow to enable dev mode on the module
Dev mode is used to allow some application to do custom setup in development mode (allow insecure certificates for example)
type: boolean
imagePullSecrets:
items:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?
type: string
type: object
x-kubernetes-map-type: atomic
type: array
initContainers:
items:
description: A single application container that you want to run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ spec:
- organizationID
- serverURL
- stackID
- tls
type: object
status:
description: StargateStatus defines the observed state of Stargate
Expand Down
6 changes: 4 additions & 2 deletions internal/resources/auths/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/formancehq/operator/internal/resources/registries"

"github.com/formancehq/go-libs/v2/collectionutils"
"github.com/formancehq/operator/api/formance.com/v1beta1"
Expand All @@ -30,7 +31,7 @@ func HashFromHash(o ...string) string {
}

func createDeployment(ctx Context, stack *v1beta1.Stack, auth *v1beta1.Auth, database *v1beta1.Database,
configMap *corev1.ConfigMap, image string, version string, clients []*v1beta1.AuthClient) error {
configMap *corev1.ConfigMap, imageConfiguration *registries.ImageConfiguration, version string, clients []*v1beta1.AuthClient) error {
annotations := map[string]string{
"config-hash": HashFromConfigMaps(configMap),
}
Expand Down Expand Up @@ -150,11 +151,12 @@ func createDeployment(ctx Context, stack *v1beta1.Stack, auth *v1beta1.Auth, dat
Annotations: annotations,
},
Spec: corev1.PodSpec{
ImagePullSecrets: imageConfiguration.PullSecrets,
Containers: []corev1.Container{{
Name: "auth",
Args: []string{"serve"},
Env: env,
Image: image,
Image: imageConfiguration.GetFullImageName(),
VolumeMounts: []corev1.VolumeMount{
NewVolumeMount("config", "/config", true),
},
Expand Down
25 changes: 6 additions & 19 deletions internal/resources/auths/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ limitations under the License.
package auths

import (
"github.com/davecgh/go-spew/spew"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
. "github.com/formancehq/go-libs/v2/collectionutils"
"github.com/formancehq/operator/api/formance.com/v1beta1"
. "github.com/formancehq/operator/internal/core"
"github.com/formancehq/operator/internal/resources/databases"
"github.com/formancehq/operator/internal/resources/gatewayhttpapis"
"github.com/formancehq/operator/internal/resources/jobs"
"github.com/formancehq/operator/internal/resources/registries"
"github.com/formancehq/operator/internal/resources/settings"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -79,26 +78,14 @@ func Reconcile(ctx Context, stack *v1beta1.Stack, auth *v1beta1.Auth, version st
return NewPendingError().WithMessage("database is not ready")
}

image, err := registries.GetImage(ctx, stack, "auth", version)
imageConfiguration, err := registries.GetFormanceImage(ctx, stack, "auth", version)
if err != nil {
return errors.Wrap(err, "resolving image")
return errors.Wrap(err, "resolving image configuration")
}
spew.Dump(imageConfiguration)

if IsGreaterOrEqual(version, "v2.0.0-rc.5") && databases.GetSavedModuleVersion(database) != version {
serviceAccountName, err := settings.GetAWSServiceAccount(ctx, stack.Name)
if err != nil {
return errors.Wrap(err, "getting service account name")
}

migrateContainer, err := databases.MigrateDatabaseContainer(ctx, stack, image, database)
if err != nil {
return errors.Wrap(err, "creating migrate container")
}

if err := jobs.Handle(ctx, auth, "migrate",
migrateContainer,
jobs.WithServiceAccount(serviceAccountName),
); err != nil {
if err := databases.Migrate(ctx, stack, auth, imageConfiguration, database); err != nil {
return err
}

Expand All @@ -107,7 +94,7 @@ func Reconcile(ctx Context, stack *v1beta1.Stack, auth *v1beta1.Auth, version st
}
}

if err := createDeployment(ctx, stack, auth, database, configMap, image, version, authClients); err != nil {
if err := createDeployment(ctx, stack, auth, database, configMap, imageConfiguration, version, authClients); err != nil {
return errors.Wrap(err, "creating deployment")
}

Expand Down
5 changes: 3 additions & 2 deletions internal/resources/benthos/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,11 @@ func createDeployment(ctx Context, stack *v1beta1.Stack, b *v1beta1.Benthos) err
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
InitContainers: b.Spec.InitContainers,
ImagePullSecrets: append(benthosImage.PullSecrets, b.Spec.ImagePullSecrets...),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen if both are fullfilled ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I have understood of the doc, each secret will be tested for each image

InitContainers: b.Spec.InitContainers,
Comment on lines +323 to +324

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the same strategy as other container ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I have not understood that point

Containers: []corev1.Container{{
Name: "benthos",
Image: benthosImage,
Image: benthosImage.GetFullImageName(),
Env: env,
Command: cmd,
Ports: []corev1.ContainerPort{{
Expand Down
Loading