-
Notifications
You must be signed in to change notification settings - Fork 0
Sidecar experimental #157
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
Sidecar experimental #157
Conversation
Ready for a merge if this direction is appreciated: Shift the logic of global sidecars configmap to helm yaml. |
postgres-fluentbit-requests-memory: {{ .Values.sidecars.fluentbit.resources.requests.memory | quote }} | ||
postgres-fluentbit-limits-cpu: {{ .Values.sidecars.fluentbit.resources.limits.cpu | quote }} | ||
postgres-fluentbit-limits-memory: {{ .Values.sidecars.fluentbit.resources.limits.memory | quote }} | ||
per-namespace-sidecars-configmap-name: {{ .Values.sidecars.perNamespaceConfigmapName | quote }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this into the operatormanager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This item is removed and instead derived dynamically in go code.
|
||
sccm := &v1.ConfigMap{} | ||
if err := m.SetName(sccm, pg.SidecarsCMName); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this var
to operatormanager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, when go code and yaml share a variable, use the one in the yaml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, the name is dynamically derived.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it's getting even more complicated? we create that configmap ourselves, and then derive it's name from another config we also created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final decision: Use hard-coded const
.
Protocol: v1.ProtocolTCP, | ||
TargetPort: intstr.IntOrString{ | ||
Type: intstr.String, | ||
StrVal: "exporter", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe derive this value from the container definition? If someone changes the configmap an renames this port there, this service won't work anymore...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configurable .Values.sidecars.exporter.containerPort
in values.yaml is used now.
api/v1/postgres_types.go
Outdated
// Deal with dynamically assigned name | ||
for i := range sidecars { | ||
for j := range sidecars[i].Env { | ||
if sidecars[i].Env[j].Name == "DATA_SOURCE_PASS" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check should be more general: If there is a sidecars[i].Env[j].ValueFrom, we should then check if it is of the kind SecretKeyRef
, and if so, we should proceed.
This implementation is just a workaround for one specific case.
for i := range sidecars { | ||
for j := range sidecars[i].Env { | ||
if sidecars[i].Env[j].ValueFrom != nil && sidecars[i].Env[j].ValueFrom.SecretKeyRef != nil { | ||
sidecars[i].Env[j].ValueFrom.SecretKeyRef.Name = "postgres." + p.ToPeripheralResourceName() + ".credentials" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still hardcoded for this usecase. I would prefer if this was completely generic. The name of the Secret should move back into the YAML/ConfigMap (the operator already supports the use of variables, in this case that string would look something like postgres.{{ main.teamid }}-{{ main.name }}.credentials
).
And while you're at it, you could also add ConfigMapKeyRef
, FieldRef
and ResourceFieldRef
(https://pkg.go.dev/k8s.io/api@v0.20.4/core/v1?utm_source=gopls#EnvVarSource).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we talk about it: remove that complete logic and only use postgres.{{ main.teamid }}-{{ main.name }}.credentials
in the ConfigMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, my bad: Try {cluster}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! The current setting in the ConfigMap
is as follows: secret_name_template: '{username}.{cluster}.credentials'
We can't use this feature in this case.
@@ -683,3 +703,19 @@ func (m *OperatorManager) UpdateAllOperators(ctx context.Context) error { | |||
m.log.Info("Done updating postgres operators in managed namespaces") | |||
return nil | |||
} | |||
|
|||
func perNamespaceSidecarsConfigMapName(cm *v1.ConfigMap) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also talk about this, as already mentioned above. that looks too complicated to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, use hard-coded const
instead.
|
||
sccm := &v1.ConfigMap{} | ||
if err := m.SetName(sccm, pg.SidecarsCMName); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it's getting even more complicated? we create that configmap ourselves, and then derive it's name from another config we also created?
Tests:
Thus, merge this PR. |
@majst01 @eberlep
This branch shows the possibility of having the items in
ConfigMap
aligned with yaml manifests of target golang struct and then unmarshal them in the code so that we avoid setting the values manually. We might not need to merge this branch into main, but it serves as an example for further discussion.