Skip to content

Commit df4678d

Browse files
authored
Merge branch 'main' into K8SPG-708-remove-hardcoded-image
2 parents 95834aa + 39ad349 commit df4678d

116 files changed

Lines changed: 1579 additions & 3826 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.next.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ linters:
1010
enable:
1111
- contextcheck
1212
- err113
13-
- errchkjson
1413
- gocritic
1514
- godot
1615
- godox
@@ -28,13 +27,16 @@ linters:
2827
- wastedassign
2928

3029
issues:
30+
exclude-rules:
31+
# We call external linters when they are installed: Flake8, ShellCheck, etc.
32+
- linters: [gosec]
33+
path: '_test[.]go$'
34+
text: 'G204: Subprocess launched with variable'
35+
3136
# https://github.com/golangci/golangci-lint/issues/2239
3237
exclude-use-default: false
3338

3439
linters-settings:
35-
errchkjson:
36-
check-error-free-encoding: true
37-
3840
thelper:
3941
# https://github.com/kulti/thelper/issues/27
4042
tb: { begin: true, first: true }

.golangci.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
linters:
44
disable:
55
- contextcheck
6-
- errchkjson
76
- gci
87
- gofumpt
98
- goimports
@@ -47,6 +46,15 @@ linters-settings:
4746
- pkg: github.com/percona/percona-postgresql-operator/internal/testing/*
4847
desc: The "internal/testing" packages should be used only in tests.
4948

49+
tests:
50+
files: ['$test']
51+
deny:
52+
- pkg: github.com/pkg/errors
53+
desc: Use the "errors" package unless you are interacting with stack traces.
54+
55+
errchkjson:
56+
check-error-free-encoding: true
57+
5058
exhaustive:
5159
default-signifies-exhaustive: true
5260

@@ -73,6 +81,10 @@ run:
7381
build-tags:
7482
- envtest
7583
issues:
76-
exclude-dirs:
77-
- pkg/generated
78-
- hack
84+
exclude-generated: strict
85+
exclude-rules:
86+
# These value types have unmarshal methods.
87+
# https://github.com/raeperd/recvcheck/issues/7
88+
- linters: [recvcheck]
89+
path: internal/pki/pki.go
90+
text: 'methods of "(Certificate|PrivateKey)"'

Makefile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ PGMONITOR_DIR ?= hack/tools/pgmonitor
99
PGMONITOR_VERSION ?= v4.11.0
1010
QUERIES_CONFIG_DIR ?= hack/tools/queries
1111

12-
EXTERNAL_SNAPSHOTTER_DIR ?= hack/tools/external-snapshotter
13-
EXTERNAL_SNAPSHOTTER_VERSION ?= v8.0.1
14-
1512
# Buildah's "build" used to be "bud". Use the alias to be compatible for a while.
1613
BUILDAH_BUILD ?= buildah bud
1714

@@ -56,12 +53,6 @@ get-pgmonitor:
5653
cp -r '$(PGMONITOR_DIR)/postgres_exporter/common/.' '${QUERIES_CONFIG_DIR}'
5754
cp '$(PGMONITOR_DIR)/postgres_exporter/linux/queries_backrest.yml' '${QUERIES_CONFIG_DIR}'
5855

59-
.PHONY: get-external-snapshotter
60-
get-external-snapshotter:
61-
git -C '$(dir $(EXTERNAL_SNAPSHOTTER_DIR))' clone https://github.com/kubernetes-csi/external-snapshotter.git || git -C '$(EXTERNAL_SNAPSHOTTER_DIR)' fetch origin
62-
@git -C '$(EXTERNAL_SNAPSHOTTER_DIR)' checkout '$(EXTERNAL_SNAPSHOTTER_VERSION)'
63-
@git -C '$(EXTERNAL_SNAPSHOTTER_DIR)' config pull.ff only
64-
6556
.PHONY: clean
6657
clean: ## Clean resources
6758
clean: clean-deprecated
@@ -209,7 +200,7 @@ check: get-pgmonitor
209200
check-envtest: ## Run check using envtest and a mock kube api
210201
check-envtest: ENVTEST_USE = hack/tools/setup-envtest --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION)
211202
check-envtest: SHELL = bash
212-
check-envtest: get-pgmonitor get-external-snapshotter
203+
check-envtest: get-pgmonitor tools/setup-envtest
213204
GOBIN='$(CURDIR)/hack/tools' $(GO) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
214205
@$(ENVTEST_USE) --print=overview && echo
215206
source <($(ENVTEST_USE) --print=env) && PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \
@@ -221,7 +212,7 @@ check-envtest: get-pgmonitor get-external-snapshotter
221212
# make check-envtest-existing PGO_TEST_TIMEOUT_SCALE=1.2
222213
.PHONY: check-envtest-existing
223214
check-envtest-existing: ## Run check using envtest and an existing kube api
224-
check-envtest-existing: get-pgmonitor get-external-snapshotter
215+
check-envtest-existing: get-pgmonitor
225216
check-envtest-existing: createnamespaces
226217
kubectl apply --server-side -k ./config/dev
227218
USE_EXISTING_CLUSTER=true PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \

build/crd/crunchy/generated/postgres-operator.crunchydata.com_pgupgrades.yaml

Lines changed: 0 additions & 2703 deletions
This file was deleted.

build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20451,6 +20451,10 @@ spec:
2045120451
type: string
2045220452
type: array
2045320453
x-kubernetes-list-type: set
20454+
grantPublicSchemaAccess:
20455+
description: Grant the user access to the public schema in each
20456+
database listed under `databases`.
20457+
type: boolean
2045420458
name:
2045520459
description: |-
2045620460
The name of this PostgreSQL user. The value may contain only lowercase
@@ -20829,10 +20833,6 @@ spec:
2082920833
type:
2083020834
description: The pgBackRest backup type for this Job
2083120835
type: string
20832-
required:
20833-
- cronJobName
20834-
- repo
20835-
- type
2083620836
type: object
2083720837
type: array
2083820838
type: object

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ spec:
5858
properties:
5959
autoCreateUserSchema:
6060
description: |-
61-
Whether or not the cluster has schemas automatically created for the user
62-
defined in `spec.users` for all of the databases listed for that user.
61+
Indicates whether schemas are automatically created for the user
62+
specified in `spec.users` across all databases associated with that user.
6363
type: boolean
6464
backups:
6565
description: PostgreSQL backup configuration
@@ -18252,6 +18252,10 @@ spec:
1825218252
type: string
1825318253
type: array
1825418254
x-kubernetes-list-type: set
18255+
grantPublicSchemaAccess:
18256+
description: Grant the user access to the public schema in each
18257+
database listed under `databases`.
18258+
type: boolean
1825518259
name:
1825618260
description: |-
1825718261
The name of this PostgreSQL user. The value may contain only lowercase
@@ -18303,6 +18307,11 @@ spec:
1830318307
- instances
1830418308
- postgresVersion
1830518309
type: object
18310+
x-kubernetes-validations:
18311+
- message: PostgresVersion must be >= 15 if grantPublicSchemaAccess exists
18312+
and is true
18313+
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
18314+
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
1830618315
status:
1830718316
properties:
1830818317
host:

cmd/pgbackrest/main.go

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616
*/
1717

1818
import (
19-
"bytes"
2019
"context"
2120
"io"
2221
"os"
@@ -96,18 +95,13 @@ func main() {
9695
cmd := createPGBackRestCommand(cfg)
9796
log.Infof("command to execute is [%s]", strings.Join(cmd, " "))
9897

99-
var output, stderr string
10098
// now run the proper exec command depending on whether or not the config hashes should first
10199
// be compared prior to executing the PGBackRest command
102100
if !cfg.compareHash {
103-
output, stderr, err = runCommand(ctx, k, cfg, cmd)
101+
err = runCommand(ctx, k, cfg, cmd)
104102
} else {
105-
output, stderr, err = compareHashAndRunCommand(ctx, k, cfg, cmd)
103+
err = compareHashAndRunCommand(ctx, k, cfg, cmd)
106104
}
107-
108-
// log any output and check for errors
109-
log.Info("output=[" + output + "]")
110-
log.Info("stderr=[" + stderr + "]")
111105
if err != nil {
112106
log.Fatal(err)
113107
}
@@ -117,13 +111,11 @@ func main() {
117111

118112
// Exec returns the stdout and stderr from running a command inside an existing
119113
// container.
120-
func (k *KubeAPI) Exec(ctx context.Context, namespace, pod, container string, stdin io.Reader, command []string) (string, string, error) {
121-
var stdout, stderr bytes.Buffer
122-
114+
func (k *KubeAPI) Exec(ctx context.Context, namespace, pod, container string, stdin io.Reader, command []string) error {
123115
Scheme := runtime.NewScheme()
124116
if err := corev1.AddToScheme(Scheme); err != nil {
125117
log.Error(err)
126-
return "", "", err
118+
return err
127119
}
128120
ParameterCodec := runtime.NewParameterCodec(Scheme)
129121

@@ -140,15 +132,58 @@ func (k *KubeAPI) Exec(ctx context.Context, namespace, pod, container string, st
140132

141133
exec, err := remotecommand.NewSPDYExecutor(k.Config, "POST", request.URL())
142134

143-
if err == nil {
144-
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
145-
Stdin: stdin,
146-
Stdout: &stdout,
147-
Stderr: &stderr,
148-
})
149-
}
135+
stdoutReader, stdoutWriter := io.Pipe()
136+
defer func() {
137+
if err := stdoutWriter.Close(); err != nil {
138+
log.Errorf("error closing stdoutWriter: %v", err)
139+
}
140+
}()
141+
142+
stderrReader, stderrWriter := io.Pipe()
143+
defer func() {
144+
if err := stderrWriter.Close(); err != nil {
145+
log.Errorf("error closing stderrWriter: %v", err)
146+
}
147+
}()
148+
149+
go streamUsingPrefix("[pgbackrest:stdout]", stdoutReader)
150+
go streamUsingPrefix("[pgbackrest:stderr]", stderrReader)
151+
152+
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
153+
Stdin: stdin,
154+
Stdout: stdoutWriter,
155+
Stderr: stderrWriter,
156+
})
150157

151-
return stdout.String(), stderr.String(), err
158+
return err
159+
}
160+
161+
// streamUsingPrefix reads from an io.Reader line by line and logs each line
162+
// prefixing it with a custom label provided as input.
163+
func streamUsingPrefix(prefix string, reader io.Reader) {
164+
buf := make([]byte, 4096)
165+
line := ""
166+
for {
167+
n, err := reader.Read(buf)
168+
if n > 0 {
169+
line += string(buf[:n])
170+
for strings.Contains(line, "\n") {
171+
idx := strings.Index(line, "\n")
172+
part := line[:idx]
173+
log.Infof("%s %s", prefix, part)
174+
line = line[idx+1:]
175+
}
176+
}
177+
if err != nil {
178+
if err != io.EOF {
179+
log.Errorf("%s error reading: %v", prefix, err)
180+
}
181+
break
182+
}
183+
}
184+
if line != "" {
185+
log.Infof("%s %s", prefix, line)
186+
}
152187
}
153188

154189
func NewConfig() (*rest.Config, error) {
@@ -313,7 +348,7 @@ func createPGBackRestCommand(cfg config) []string {
313348
// command. Only if the hashes match will the pgBackRest command be run, otherwise and error will
314349
// be written and exit code 1 will be returned. This is done to ensure a pgBackRest command is only
315350
// run when it can be verified that the exepected configuration is present.
316-
func compareHashAndRunCommand(ctx context.Context, kubeapi *KubeAPI, cfg config, cmd []string) (string, string, error) {
351+
func compareHashAndRunCommand(ctx context.Context, kubeapi *KubeAPI, cfg config, cmd []string) error {
317352
// the base script used in both the local and exec commands created below
318353
baseScript := `
319354
shopt -s globstar
@@ -352,7 +387,7 @@ fi
352387

353388
// runCommand runs the provided pgBackRest command according to the configuration
354389
// provided
355-
func runCommand(ctx context.Context, kubeapi *KubeAPI, cfg config, cmd []string) (string, string, error) {
390+
func runCommand(ctx context.Context, kubeapi *KubeAPI, cfg config, cmd []string) error {
356391
bashCmd := []string{"bash"}
357392
reader := strings.NewReader(strings.Join(cmd, " "))
358393
return kubeapi.Exec(ctx, cfg.namespace, cfg.podName, cfg.container, reader, bashCmd)

cmd/postgres-operator/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ func main() {
9292
assertNoError(err)
9393

9494
assertNoError(features.Set(os.Getenv("PGO_FEATURE_GATES")))
95-
log.Info("feature gates enabled", "PGO_FEATURE_GATES", features.String())
95+
ctx = feature.NewContext(ctx, features)
96+
log.Info("feature gates",
97+
// These are set by the user
98+
"PGO_FEATURE_GATES", feature.ShowAssigned(ctx),
99+
// These are enabled, including features that are on by default
100+
"enabled", feature.ShowEnabled(ctx))
96101

97102
cruntime.SetLogger(log)
98103

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ spec:
463463
properties:
464464
autoCreateUserSchema:
465465
description: |-
466-
Whether or not the cluster has schemas automatically created for the user
467-
defined in `spec.users` for all of the databases listed for that user.
466+
Indicates whether schemas are automatically created for the user
467+
specified in `spec.users` across all databases associated with that user.
468468
type: boolean
469469
backups:
470470
description: PostgreSQL backup configuration
@@ -18657,6 +18657,10 @@ spec:
1865718657
type: string
1865818658
type: array
1865918659
x-kubernetes-list-type: set
18660+
grantPublicSchemaAccess:
18661+
description: Grant the user access to the public schema in each
18662+
database listed under `databases`.
18663+
type: boolean
1866018664
name:
1866118665
description: |-
1866218666
The name of this PostgreSQL user. The value may contain only lowercase
@@ -18708,6 +18712,11 @@ spec:
1870818712
- instances
1870918713
- postgresVersion
1871018714
type: object
18715+
x-kubernetes-validations:
18716+
- message: PostgresVersion must be >= 15 if grantPublicSchemaAccess exists
18717+
and is true
18718+
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
18719+
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
1871118720
status:
1871218721
properties:
1871318722
host:

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20349,6 +20349,10 @@ spec:
2034920349
type: string
2035020350
type: array
2035120351
x-kubernetes-list-type: set
20352+
grantPublicSchemaAccess:
20353+
description: Grant the user access to the public schema in each
20354+
database listed under `databases`.
20355+
type: boolean
2035220356
name:
2035320357
description: |-
2035420358
The name of this PostgreSQL user. The value may contain only lowercase
@@ -20727,10 +20731,6 @@ spec:
2072720731
type:
2072820732
description: The pgBackRest backup type for this Job
2072920733
type: string
20730-
required:
20731-
- cronJobName
20732-
- repo
20733-
- type
2073420734
type: object
2073520735
type: array
2073620736
type: object

0 commit comments

Comments
 (0)