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
5 changes: 3 additions & 2 deletions .github/workflows/latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ jobs:
go-version-file: 'go.mod'

- name: Lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v9
with:
args: -p bugs -p unused --timeout=5m
only-new-issues: true
args: --timeout=5m

- name: Build and push Docker image
run: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ jobs:
go-version-file: 'go.mod'

- name: Lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v9
with:
args: -p bugs -p unused --timeout=5m
only-new-issues: true
args: --timeout=5m

- name: Get Kubebuilder Version
id: get-kubebuilder-version
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ jobs:
go-version-file: 'go.mod'

- name: Lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v9
with:
args: -p bugs -p unused --timeout=5m
args: --timeout=5m
only-new-issues: true

- name: Build and push Docker image
run: |
Expand Down
98 changes: 98 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
version: "2"
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
- durationcheck
- err113
- errchkjson
- errname
- errorlint
- exhaustive
- exhaustruct
- exptostd
- forbidigo
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gochecksumtype
- goconst
- gocritic
- godox
- goheader
- gomoddirectives
- gomodguard_v2
- goprintffuncname
- gosec
- gosmopolitan
- grouper
- iface
- importas
- inamedparam
- interfacebloat
- intrange
- ireturn
- loggercheck
- makezero
- mirror
- misspell
- musttag
- nakedret
- nilerr
- nilnesserr
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- paralleltest
- predeclared
- promlinter
- protogetter
- reassign
- recvcheck
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagalign
- testifylint
- testpackage
- tparallel
- unconvert
- unparam
- usestdlibvars
- wastedassign
- wrapcheck
- zerologlint
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,4 @@ localkube-reinstall-postgreslet: localkube-load-image
helm upgrade --install postgreslet metal-stack-30/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig-ctrl --kubeconfig ./kubeconfig-svc

lint:
golangci-lint run -p bugs -p unused --timeout=5m
golangci-lint run --timeout=5m --fix --new-from-merge-base=main
56 changes: 31 additions & 25 deletions api/v1/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const (
defaultPostgresParamValueWalKeepSize = "1GB"
defaultPostgresParamValuePGStatStatementsMax = "500"
defaultSelectorDisableValue = "selector-disabled"
defaultPostgresParamValuePasswordEncryption = "scram-sha-256" // nolint
defaultPostgresParamValuePasswordEncryption = "scram-sha-256" //nolint
defaultPostgresParamValueLogMinErrorStatement = "WARNING"
defaultPostgresParamValueLogErrorVerbosity = "VERBOSE"
defaultPostgresParamValueLogLinePrefix = "%m [%p]: [%l-1] db=%d,user=%u,app=%a,client=%h "
Expand Down Expand Up @@ -319,7 +319,7 @@ func (p *Postgres) HasSourceRanges() bool {

// IsBeingDeleted returns true if the deletion-timestamp is set
func (p *Postgres) IsBeingDeleted() bool {
return !p.ObjectMeta.DeletionTimestamp.IsZero()
return !p.DeletionTimestamp.IsZero()
}

// ToCWNP returns CRD ClusterwideNetworkPolicy derived from CRD Postgres
Expand Down Expand Up @@ -664,6 +664,7 @@ func (p *Postgres) ToDNSName(tlsSubDomain string) string {
if len(name) > maxLen {
name = name[:maxLen]
}

return name + "." + tlsSubDomain
}

Expand Down Expand Up @@ -699,43 +700,43 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
z.Spec.DockerImage = image
}
z.Spec.NumberOfInstances = p.Spec.NumberOfInstances
z.Spec.PostgresqlParam.PgVersion = p.Spec.Version
z.Spec.PgVersion = p.Spec.Version

// initialize the parameters
z.Spec.PostgresqlParam.Parameters = map[string]string{}
z.Spec.Parameters = map[string]string{}
// enable default audit logs (if not configured otherwise)
if p.Spec.AuditLogs == nil || *p.Spec.AuditLogs {
enableAuditLogs(z.Spec.PostgresqlParam.Parameters)
enableAuditLogs(z.Spec.Parameters)
}
// set some default postgres parameters
setDefaultPostgresParams(z.Spec.PostgresqlParam.Parameters, p.Spec.Version)
setDefaultPostgresParams(z.Spec.Parameters, p.Spec.Version)
// now set the given generic parameters (and potentially allow overwriting of default postgres params or audit log params)
setPostgresParams(z.Spec.PostgresqlParam.Parameters, p.Spec.PostgresParams, pgParamBlockList)
setPostgresParams(z.Spec.Parameters, p.Spec.PostgresParams, pgParamBlockList)
// finally, overwrite the (special to us) shared buffer parameter
setSharedBufferSize(z.Spec.PostgresqlParam.Parameters, p.Spec.Size.SharedBuffer)
setSharedBufferSize(z.Spec.Parameters, p.Spec.Size.SharedBuffer)

z.Spec.Resources = &zalando.Resources{}
cpuReq, err := p.calculateCPURequests(p.Spec.Size.CPU, cpuRequestsPercentage)
if err != nil {
return nil, fmt.Errorf("failed to convert to unstructured zalando postgresql: %w", err)
}
z.Spec.Resources.ResourceRequests.CPU = ptr.To(cpuReq)
z.Spec.Resources.ResourceRequests.Memory = ptr.To(p.Spec.Size.Memory)
z.Spec.Resources.ResourceLimits.CPU = ptr.To(p.Spec.Size.CPU)
z.Spec.Resources.ResourceLimits.Memory = ptr.To(p.Spec.Size.Memory)
z.Spec.ResourceRequests.CPU = ptr.To(cpuReq)
z.Spec.ResourceRequests.Memory = ptr.To(p.Spec.Size.Memory)
z.Spec.ResourceLimits.CPU = ptr.To(p.Spec.Size.CPU)
z.Spec.ResourceLimits.Memory = ptr.To(p.Spec.Size.Memory)
z.Spec.TeamID = p.generateTeamID()
z.Spec.Volume.Size = p.Spec.Size.StorageSize
z.Spec.Size = p.Spec.Size.StorageSize
if p.Spec.StorageClass != nil {
z.Spec.Volume.StorageClass = *p.Spec.StorageClass
z.Spec.StorageClass = *p.Spec.StorageClass
} else {
z.Spec.Volume.StorageClass = sc
z.Spec.StorageClass = sc
}

z.Spec.Patroni.TTL = patroniTTL
z.Spec.Patroni.LoopWait = patroniLoopWait
z.Spec.Patroni.RetryTimeout = patroniRetryTimeout
z.Spec.Patroni.SynchronousMode = true
z.Spec.Patroni.SynchronousModeStrict = false
z.Spec.TTL = patroniTTL
z.Spec.LoopWait = patroniLoopWait
z.Spec.RetryTimeout = patroniRetryTimeout
z.Spec.SynchronousMode = true
z.Spec.SynchronousModeStrict = false

// required with image ermajn/postgres-operator:v1.6.0-20-g1cc71663-dirty
// see https://github.com/fi-ts/postgreslet/issues/293
Expand Down Expand Up @@ -866,15 +867,15 @@ func (p *Postgres) ToZalandoPostgresqlMatchingLabels() client.MatchingLabels {
}

func (p *Postgres) HasFinalizer(finalizerName string) bool {
return containsElem(p.ObjectMeta.Finalizers, finalizerName)
return containsElem(p.Finalizers, finalizerName)
}

func (p *Postgres) AddFinalizer(finalizerName string) {
p.ObjectMeta.Finalizers = append(p.ObjectMeta.Finalizers, finalizerName)
p.Finalizers = append(p.Finalizers, finalizerName)
}

func (p *Postgres) RemoveFinalizer(finalizerName string) {
p.ObjectMeta.Finalizers = removeElem(p.ObjectMeta.Finalizers, finalizerName)
p.Finalizers = removeElem(p.Finalizers, finalizerName)
}

func containsElem(ss []string, s string) bool {
Expand All @@ -883,6 +884,7 @@ func containsElem(ss []string, s string) bool {
return true
}
}

return false
}

Expand All @@ -893,6 +895,7 @@ func removeElem(ss []string, s string) (out []string) {
}
out = append(out, elem)
}

return
}

Expand Down Expand Up @@ -941,6 +944,7 @@ func (p *Postgres) buildSidecars(c *corev1.ConfigMap) []zalando.Sidecar {
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 = PostgresConfigMonitoringUsername + "." + p.ToPeripheralResourceName() + ".credentials"

break
}
}
Expand Down Expand Up @@ -969,6 +973,7 @@ func (p *Postgres) IsReplicationPrimaryOrStandalone() bool {
// nothing is configured, or we are the leader. nothing to do.
return true
}

return false
}

Expand All @@ -977,6 +982,7 @@ func (p *Postgres) IsReplicationTarget() bool {
// sth is configured and we are not the leader
return true
}

return false
}

Expand Down Expand Up @@ -1125,13 +1131,13 @@ func (p *Postgres) calculateCPURequests(c string, percentage int) (string, error
// calculate the percentage
value := int64((milliValue / int64(100)) * int64(percentage))

//return the calculated cpu request, making sure it is not higher than the given input value
// return the calculated cpu request, making sure it is not higher than the given input value
return resource.NewMilliQuantity(min(value, milliValue), resource.BinarySI).String(), nil
}

// sanitize a string so it can be used as a label value. if the string is valid, it
// will be returned unmodified. otherwise all illegal character will be replace with "_"
// where multiple "_" will be shrinked to a single one. the string must also start and end
// where multiple "_" will be shrunk to a single one. the string must also start and end
// with a alphanumeric character. last but not least, a label value must not be longer than 63
// characters.
func sanitizeLabelValue(v string) string {
Expand Down
11 changes: 3 additions & 8 deletions api/v1/postgres_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func Test_setSharedBufferSize(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt // pin!
t.Run(tt.name, func(t *testing.T) {
parameters := map[string]string{}

Expand Down Expand Up @@ -131,9 +130,8 @@ func TestPostgres_generateTeamID(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt // pin!
t.Run(tt.name, func(t *testing.T) {
var dnsRegExp *regexp.Regexp = regexp.MustCompile("^[a-z]([-a-z0-9]*[a-z0-9])?$")
dnsRegExp := regexp.MustCompile("^[a-z]([-a-z0-9]*[a-z0-9])?$")
p := &Postgres{
Spec: PostgresSpec{
ProjectID: tt.projectID,
Expand Down Expand Up @@ -194,9 +192,8 @@ func TestPostgres_ToPeripheralResourceName(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt // pin!
t.Run(tt.name, func(t *testing.T) {
var dnsRegExp *regexp.Regexp = regexp.MustCompile("^[a-z]([-a-z0-9]*[a-z0-9])?$")
dnsRegExp := regexp.MustCompile("^[a-z]([-a-z0-9]*[a-z0-9])?$")
p := &Postgres{
ObjectMeta: v1.ObjectMeta{
Name: tt.postgresName,
Expand All @@ -210,7 +207,7 @@ func TestPostgres_ToPeripheralResourceName(t *testing.T) {
if !dnsRegExp.MatchString(got) {
t.Errorf("Postgres.ToPeripheralResourceName() got %v, not a valid DNS name", got)
}
//This resource name will be used as part of the name of other resources, hence we need to limit it's length,
// This resource name will be used as part of the name of other resources, hence we need to limit it's length,
// e.g. "postgres.bce25ade7552494c-33d21de46d284ea6bec0.credentials"
maxLen := 37
if len(got) > maxLen {
Expand Down Expand Up @@ -378,7 +375,6 @@ func TestPostgresRestoreTimestamp_ToUnstructuredZalandoPostgresql(t *testing.T)
},
}
for _, tt := range tests {
tt := tt // pin!
t.Run(tt.name, func(t *testing.T) {
p := &Postgres{
Spec: tt.spec,
Expand Down Expand Up @@ -445,7 +441,6 @@ func Test_calculateCPURequests(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt // pin!
t.Run(tt.name, func(t *testing.T) {
p := &Postgres{
Spec: PostgresSpec{
Expand Down
Loading
Loading