Skip to content

Commit 240077c

Browse files
armrufcanovaimnencialeonardoce
authored
feat(spike): restore (#29)
Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Francesco Canovai <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Francesco Canovai <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]>
1 parent 5d0038e commit 240077c

File tree

35 files changed

+1778
-398
lines changed

35 files changed

+1778
-398
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= controller:latest
2+
IMG ?= plugin-barman-cloud:latest
33
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
44
ENVTEST_K8S_VERSION = 1.31.0
55

cmd/manager/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package main is the entrypoint for the plugin
2+
package main

cmd/manager/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/cloudnative-pg/machinery/pkg/log"
8+
"github.com/spf13/cobra"
9+
10+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/instance"
11+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/operator"
12+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cmd/restore"
13+
)
14+
15+
func main() {
16+
cobra.EnableTraverseRunHooks = true
17+
18+
logFlags := &log.Flags{}
19+
rootCmd := &cobra.Command{
20+
Use: "manager [cmd]",
21+
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
22+
logFlags.ConfigureLogging()
23+
return nil
24+
},
25+
}
26+
27+
logFlags.AddFlags(rootCmd.PersistentFlags())
28+
29+
rootCmd.AddCommand(instance.NewCmd())
30+
rootCmd.AddCommand(operator.NewCmd())
31+
rootCmd.AddCommand(restore.NewCmd())
32+
33+
if err := rootCmd.Execute(); err != nil {
34+
fmt.Println(err)
35+
os.Exit(1)
36+
}
37+
}

cmd/operator/main.go

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

config/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ rules:
4040
- get
4141
- patch
4242
- update
43+
- apiGroups:
44+
- postgresql.cnpg.io
45+
resources:
46+
- backups
47+
verbs:
48+
- get
49+
- list
50+
- watch
4351
- apiGroups:
4452
- rbac.authorization.k8s.io
4553
resources:

containers/Dockerfile.plugin

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.23 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -12,17 +12,17 @@ COPY ../go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY ../cmd/operator/main.go cmd/operator/main.go
16-
COPY ../api api/
17-
COPY ../internal internal/
15+
COPY ../cmd/manager/main.go cmd/manager/main.go
16+
COPY ../api/ api/
17+
COPY ../internal/ internal/
1818

1919
# Build
2020
# the GOARCH has not a default value to allow the binary be built according to the host where the command
2121
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2222
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2323
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
2424
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
25-
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/operator/main.go
25+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go
2626

2727
# Use distroless as minimal base image to package the manager binary
2828
# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -42,7 +42,7 @@ LABEL summary="$SUMMARY" \
4242
release="1"
4343

4444
WORKDIR /
45-
COPY --from=builder /workspace/manager .
45+
COPY --from=gobuilder /workspace/manager .
4646
USER 65532:65532
4747

48-
ENTRYPOINT ["/manager"]
48+
ENTRYPOINT ["/manager"]

containers/Dockerfile.sidecar

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
# * instance plugin
55
# Both components are built before going into a distroless container
66

7+
# Build the manager binary
8+
FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder
9+
ARG TARGETOS
10+
ARG TARGETARCH
11+
12+
WORKDIR /workspace
13+
# Copy the Go Modules manifests
14+
COPY ../go.mod go.mod
15+
COPY ../go.sum go.sum
16+
# cache deps before building and copying source so that we don't need to re-download as much
17+
# and so that source changes don't invalidate our downloaded layer
18+
RUN go mod download
19+
20+
# Copy the go source
21+
COPY ../cmd/manager/main.go cmd/manager/main.go
22+
COPY ../api/ api/
23+
COPY ../internal/ internal/
24+
25+
# Build
26+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
27+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
28+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
29+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
30+
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
31+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go
32+
733
# Build barman-cloud
834
# pip will build everything inside /usr/ since this is the case
935
# we should build and then copy every file into a destination that will
@@ -19,17 +45,6 @@ RUN mkdir /new-usr/ && \
1945
cp -r --parents /usr/local/lib/ /usr/lib/*-linux-gnu/ /usr/local/bin/ \
2046
/new-usr/
2147

22-
# Build instance
23-
# This step builds a simple instance app that will manage and handle
24-
# the barman-cloud commands inside the sidecar
25-
FROM --platform=$BUILDPLATFORM golang:1.23.1 AS gobuilder
26-
ENV CGO_ENABLED=0
27-
COPY .. /src
28-
ARG TARGETOS
29-
ARG TARGETARCH
30-
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
31-
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -C /src -o /build/instance /src/cmd/instance/main.go
32-
3348
# Joint process
3449
# Now we put everything that was build from the origin into our
3550
# distroless container
@@ -49,6 +64,6 @@ LABEL summary="$SUMMARY" \
4964
release="1"
5065

5166
COPY --from=pythonbuilder /new-usr/* /usr/
52-
COPY --from=gobuilder /build/instance /usr/local/bin/instance
67+
COPY --from=gobuilder /workspace/manager /manager
5368
USER 26:26
54-
ENTRYPOINT ["/usr/local/bin/instance"]
69+
ENTRYPOINT ["/manager"]

docs/examples/cluster-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: cluster-example
55
spec:
66
instances: 3
7-
7+
imagePullPolicy: IfNotPresent
88
plugins:
99
- name: barman-cloud.cloudnative-pg.io
1010
parameters:

docs/examples/cluster-restore.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: cluster-restore
5+
spec:
6+
instances: 3
7+
imagePullPolicy: IfNotPresent
8+
9+
bootstrap:
10+
recovery:
11+
source: source
12+
13+
externalClusters:
14+
- name: source
15+
plugin:
16+
name: barman-cloud.cloudnative-pg.io
17+
parameters:
18+
barmanObjectName: minio-store
19+
serverName: cluster-example
20+
21+
storage:
22+
size: 1Gi

go.mod

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
module github.com/cloudnative-pg/plugin-barman-cloud
22

3-
go 1.22.0
3+
go 1.23
4+
5+
toolchain go1.23.1
46

57
require (
68
github.com/cloudnative-pg/barman-cloud v0.0.0-20240924124724-92831d48562a
7-
github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241001084914-829808376542
8-
github.com/cloudnative-pg/cnpg-i v0.0.0-20240924030516-c5636170f248
9-
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241002070940-e5495e9c5ed6
10-
github.com/cloudnative-pg/machinery v0.0.0-20241007093555-1e197af1f392
9+
github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241031170209-ad2b0d78a230
10+
github.com/cloudnative-pg/cnpg-i v0.0.0-20241030162745-80b6d07403c1
11+
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241014090747-e9c2b3738d19
12+
github.com/cloudnative-pg/machinery v0.0.0-20241014090714-c27747f9974b
1113
github.com/onsi/ginkgo/v2 v2.20.2
1214
github.com/onsi/gomega v1.34.2
1315
github.com/spf13/cobra v1.8.1
1416
github.com/spf13/viper v1.19.0
1517
google.golang.org/grpc v1.67.1
16-
k8s.io/api v0.31.1
17-
k8s.io/apimachinery v0.31.1
18-
k8s.io/client-go v0.31.1
19-
sigs.k8s.io/controller-runtime v0.19.0
18+
k8s.io/api v0.31.2
19+
k8s.io/apimachinery v0.31.2
20+
k8s.io/client-go v0.31.2
21+
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6
22+
sigs.k8s.io/controller-runtime v0.19.1
2023
)
2124

2225
require (
@@ -27,6 +30,7 @@ require (
2730
github.com/blang/semver/v4 v4.0.0 // indirect
2831
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2932
github.com/cespare/xxhash/v2 v2.3.0 // indirect
33+
github.com/cloudnative-pg/api v0.0.0-20241004125129-98baa9f4957b // indirect
3034
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3135
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
3236
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
@@ -70,8 +74,8 @@ require (
7074
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
7175
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
7276
github.com/pkg/errors v0.9.1 // indirect
73-
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.75.2 // indirect
74-
github.com/prometheus/client_golang v1.20.3 // indirect
77+
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.77.2 // indirect
78+
github.com/prometheus/client_golang v1.20.5 // indirect
7579
github.com/prometheus/client_model v0.6.1 // indirect
7680
github.com/prometheus/common v0.59.1 // indirect
7781
github.com/prometheus/procfs v0.15.1 // indirect
@@ -98,28 +102,27 @@ require (
98102
go.uber.org/multierr v1.11.0 // indirect
99103
go.uber.org/zap v1.27.0 // indirect
100104
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
101-
golang.org/x/net v0.29.0 // indirect
105+
golang.org/x/net v0.30.0 // indirect
102106
golang.org/x/oauth2 v0.23.0 // indirect
103107
golang.org/x/sync v0.8.0 // indirect
104-
golang.org/x/sys v0.25.0 // indirect
105-
golang.org/x/term v0.24.0 // indirect
106-
golang.org/x/text v0.18.0 // indirect
107-
golang.org/x/time v0.6.0 // indirect
108+
golang.org/x/sys v0.26.0 // indirect
109+
golang.org/x/term v0.25.0 // indirect
110+
golang.org/x/text v0.19.0 // indirect
111+
golang.org/x/time v0.7.0 // indirect
108112
golang.org/x/tools v0.25.0 // indirect
109113
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
110114
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
111115
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
112-
google.golang.org/protobuf v1.34.2 // indirect
116+
google.golang.org/protobuf v1.35.1 // indirect
113117
gopkg.in/inf.v0 v0.9.1 // indirect
114118
gopkg.in/ini.v1 v1.67.0 // indirect
115119
gopkg.in/yaml.v2 v2.4.0 // indirect
116120
gopkg.in/yaml.v3 v3.0.1 // indirect
117-
k8s.io/apiextensions-apiserver v0.31.1 // indirect
118-
k8s.io/apiserver v0.31.1 // indirect
119-
k8s.io/component-base v0.31.1 // indirect
121+
k8s.io/apiextensions-apiserver v0.31.2 // indirect
122+
k8s.io/apiserver v0.31.2 // indirect
123+
k8s.io/component-base v0.31.2 // indirect
120124
k8s.io/klog/v2 v2.130.1 // indirect
121125
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect
122-
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect
123126
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
124127
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
125128
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect

0 commit comments

Comments
 (0)