Skip to content

Commit 2f62d53

Browse files
authored
feat: sidecar role and rolebinding (#23)
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent ea6ee30 commit 2f62d53

28 files changed

+493
-104
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ help: ## Display this help.
4545

4646
.PHONY: manifests
4747
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
48-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
48+
$(CONTROLLER_GEN) rbac:roleName=plugin-barman-cloud crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4949

5050
.PHONY: generate
5151
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

api/v1/zz_generated.deepcopy.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/operator/main.go

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,97 @@
22
package main
33

44
import (
5-
"context"
65
"fmt"
76
"os"
87

98
"github.com/cloudnative-pg/machinery/pkg/log"
10-
"github.com/sourcegraph/conc/pool"
119
"github.com/spf13/cobra"
1210
"github.com/spf13/viper"
1311

1412
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator"
15-
"github.com/cloudnative-pg/plugin-barman-cloud/internal/operator/manager"
1613
)
1714

1815
func main() {
1916
cobra.EnableTraverseRunHooks = true
2017

2118
logFlags := &log.Flags{}
2219
rootCmd := &cobra.Command{
23-
Use: "plugin-barman-cloud",
20+
Use: "plugin-barman-cloud",
21+
Short: "Starts the BarmanObjectStore reconciler and the Barman Cloud CNPG-i plugin",
22+
RunE: func(cmd *cobra.Command, _ []string) error {
23+
if len(viper.GetString("sidecar-image")) == 0 {
24+
return fmt.Errorf("missing required SIDECAR_IMAGE environment variable")
25+
}
26+
27+
return operator.Start(cmd.Context())
28+
},
2429
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
2530
logFlags.ConfigureLogging()
2631
return nil
2732
},
2833
}
2934

3035
logFlags.AddFlags(rootCmd.PersistentFlags())
31-
rootCmd.AddCommand(newOperatorCommand())
32-
33-
if err := rootCmd.Execute(); err != nil {
34-
fmt.Println(err)
35-
os.Exit(1)
36-
}
37-
}
3836

39-
func newOperatorCommand() *cobra.Command {
40-
cmd := operator.NewCommand()
41-
cmd.Use = "operator"
42-
cmd.Short = "Starts the BarmanObjectStore reconciler and the Barman Cloud CNPG-i plugin"
43-
grpcServer := cmd.RunE
44-
45-
cmd.RunE = func(cmd *cobra.Command, args []string) error {
46-
operatorPool := pool.
47-
New().
48-
WithContext(cmd.Context()).
49-
WithCancelOnError().
50-
WithFirstError()
51-
operatorPool.Go(func(ctx context.Context) error {
52-
cmd.SetContext(ctx)
53-
54-
if len(viper.GetString("sidecar-image")) == 0 {
55-
return fmt.Errorf("missing required SIDECAR_IMAGE environment variable")
56-
}
57-
58-
err := grpcServer(cmd, args)
59-
return err
60-
})
61-
operatorPool.Go(manager.Start)
62-
return operatorPool.Wait()
63-
}
64-
65-
cmd.Flags().String("metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
37+
rootCmd.Flags().String("metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
6638
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
67-
_ = viper.BindPFlag("metrics-bind-address", cmd.Flags().Lookup("metrics-bind-address"))
39+
_ = viper.BindPFlag("metrics-bind-address", rootCmd.Flags().Lookup("metrics-bind-address"))
6840

69-
cmd.Flags().String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
70-
_ = viper.BindPFlag("health-probe-bind-address", cmd.Flags().Lookup("health-probe-bind-address"))
41+
rootCmd.Flags().String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
42+
_ = viper.BindPFlag("health-probe-bind-address", rootCmd.Flags().Lookup("health-probe-bind-address"))
7143

72-
cmd.Flags().Bool("leader-elect", false,
44+
rootCmd.Flags().Bool("leader-elect", false,
7345
"Enable leader election for controller manager. "+
7446
"Enabling this will ensure there is only one active controller manager.")
75-
_ = viper.BindPFlag("leader-elect", cmd.Flags().Lookup("leader-elect"))
47+
_ = viper.BindPFlag("leader-elect", rootCmd.Flags().Lookup("leader-elect"))
7648

77-
cmd.Flags().Bool("metrics-secure", true,
49+
rootCmd.Flags().Bool("metrics-secure", true,
7850
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
79-
_ = viper.BindPFlag("metrics-secure", cmd.Flags().Lookup("metrics-secure"))
51+
_ = viper.BindPFlag("metrics-secure", rootCmd.Flags().Lookup("metrics-secure"))
8052

81-
cmd.Flags().Bool("enable-http2", false,
53+
rootCmd.Flags().Bool("enable-http2", false,
8254
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
83-
_ = viper.BindPFlag("enable-http2", cmd.Flags().Lookup("enable-http2"))
55+
_ = viper.BindPFlag("enable-http2", rootCmd.Flags().Lookup("enable-http2"))
56+
57+
rootCmd.Flags().String(
58+
"plugin-path",
59+
"",
60+
"The plugins socket path",
61+
)
62+
_ = viper.BindPFlag("plugin-path", rootCmd.Flags().Lookup("plugin-path"))
63+
64+
rootCmd.Flags().String(
65+
"server-cert",
66+
"",
67+
"The public key to be used for the server process",
68+
)
69+
_ = viper.BindPFlag("server-cert", rootCmd.Flags().Lookup("server-cert"))
70+
71+
rootCmd.Flags().String(
72+
"server-key",
73+
"",
74+
"The key to be used for the server process",
75+
)
76+
_ = viper.BindPFlag("server-key", rootCmd.Flags().Lookup("server-key"))
77+
78+
rootCmd.Flags().String(
79+
"client-cert",
80+
"",
81+
"The client public key to verify the connection",
82+
)
83+
_ = viper.BindPFlag("client-cert", rootCmd.Flags().Lookup("client-cert"))
84+
85+
rootCmd.Flags().String(
86+
"server-address",
87+
"",
88+
"The address where to listen (i.e. 0:9090)",
89+
)
90+
_ = viper.BindPFlag("server-address", rootCmd.Flags().Lookup("server-address"))
8491

8592
_ = viper.BindEnv("sidecar-image", "SIDECAR_IMAGE")
8693

87-
return cmd
94+
if err := rootCmd.Execute(); err != nil {
95+
fmt.Println(err)
96+
os.Exit(1)
97+
}
8898
}

config/crd/bases/barmancloud.cnpg.io_objectstores.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
- name: v1
1818
schema:
1919
openAPIV3Schema:
20-
description: ObjectStore is the Schema for the objectstores API
20+
description: ObjectStore is the Schema for the objectstores API.
2121
properties:
2222
apiVersion:
2323
description: |-
@@ -37,7 +37,7 @@ spec:
3737
metadata:
3838
type: object
3939
spec:
40-
description: ObjectStoreSpec defines the desired state of ObjectStore
40+
description: ObjectStoreSpec defines the desired state of ObjectStore.
4141
properties:
4242
configuration:
4343
description: |-
@@ -382,7 +382,7 @@ spec:
382382
- configuration
383383
type: object
384384
status:
385-
description: ObjectStoreStatus defines the observed state of ObjectStore
385+
description: ObjectStoreStatus defines the observed state of ObjectStore.
386386
type: object
387387
type: object
388388
served: true

config/rbac/role.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRole
44
metadata:
5-
name: manager-role
5+
name: plugin-barman-cloud
66
rules:
77
- apiGroups:
88
- barmancloud.cnpg.io
@@ -30,3 +30,15 @@ rules:
3030
- get
3131
- patch
3232
- update
33+
- apiGroups:
34+
- rbac.authorization.k8s.io
35+
resources:
36+
- rolebindings
37+
- roles
38+
verbs:
39+
- create
40+
- get
41+
- list
42+
- patch
43+
- update
44+
- watch

config/rbac/role_binding.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ metadata:
44
labels:
55
app.kubernetes.io/name: plugin-barman-cloud
66
app.kubernetes.io/managed-by: kustomize
7-
name: manager-rolebinding
7+
name: plugin-barman-cloud-binding
88
roleRef:
99
apiGroup: rbac.authorization.k8s.io
1010
kind: ClusterRole
11-
name: manager-role
11+
name: plugin-barman-cloud
1212
subjects:
1313
- kind: ServiceAccount
1414
name: plugin-barman-cloud

config/samples/barmancloud_v1_objectstore.yaml

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

docs/examples/cluster-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
plugins:
99
- name: barman-cloud.cloudnative-pg.io
1010
parameters:
11-
barmanObjectStore: minio-store
11+
barmanObjectName: minio-store
1212

1313
storage:
1414
size: 1Gi

docs/examples/minio-store.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: barmancloud.cnpg.io/v1
2+
kind: ObjectStore
3+
metadata:
4+
name: minio-store
5+
spec:
6+
configuration:
7+
destinationPath: s3://backups/
8+
endpointURL: http://minio:9000
9+
s3Credentials:
10+
accessKeyId:
11+
name: minio
12+
key: ACCESS_KEY_ID
13+
secretAccessKey:
14+
name: minio
15+
key: ACCESS_SECRET_KEY
16+
wal:
17+
compression: gzip
18+
data:
19+
additionalCommandArgs:
20+
- "--min-chunk-size=5MB"
21+
- "--read-timeout=60"
22+
- "-vv"
23+

docs/minio/minio-client.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
run: mc
6+
name: mc
7+
spec:
8+
containers:
9+
- env:
10+
- name: MC_HOST_minio
11+
value: http://chooJeiroroo2noquomei2uuceisheth:ongeiqueitohL0queeLohkiur2quaing@minio:9000
12+
image: minio/mc
13+
name: mc
14+
resources: {}
15+
# Keep the pod up to exec stuff on it
16+
command:
17+
- sleep
18+
- "3600"
19+
dnsPolicy: ClusterFirst
20+
restartPolicy: Always

0 commit comments

Comments
 (0)