Skip to content

Commit d2be116

Browse files
committed
Add initial version of managed-velero-operator
1 parent b571886 commit d2be116

32 files changed

+1380
-18
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ default: gobuild
1212

1313
.PHONY: docker-build
1414
docker-build: build
15+
16+
.PHONY: generate
17+
generate:
18+
operator-sdk generate k8s
19+
operator-sdk generate openapi

build/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.12 AS builder
2+
3+
# Allow specifying a GOPROXY cache during build to speed up dependency resolution
4+
ARG GOPROXY
5+
ENV GOPROXY=$GOPROXY
6+
27
ENV OPERATOR_PATH=/go/src/github.com/openshift/managed-velero-operator
38
COPY . ${OPERATOR_PATH}
49
WORKDIR ${OPERATOR_PATH}
@@ -23,4 +28,4 @@ ENTRYPOINT ["/usr/local/bin/entrypoint"]
2328
USER ${USER_UID}
2429

2530
LABEL io.openshift.managed.name="managed-velero-operator" \
26-
io.openshift.managed.description="Operator to manage installation of Velero in OpenShift Managed environments"
31+
io.openshift.managed.description="Operator to manage installation of Velero in managed OpenShift environments"

cmd/manager/main.go

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313

1414
"github.com/openshift/managed-velero-operator/pkg/apis"
1515
"github.com/openshift/managed-velero-operator/pkg/controller"
16+
"github.com/openshift/managed-velero-operator/pkg/util/platform"
17+
"github.com/openshift/managed-velero-operator/version"
1618

1719
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
1820
kubemetrics "github.com/operator-framework/operator-sdk/pkg/kube-metrics"
@@ -24,10 +26,16 @@ import (
2426
"github.com/spf13/pflag"
2527
v1 "k8s.io/api/core/v1"
2628
"k8s.io/apimachinery/pkg/util/intstr"
29+
crclient "sigs.k8s.io/controller-runtime/pkg/client"
2730
"sigs.k8s.io/controller-runtime/pkg/client/config"
2831
"sigs.k8s.io/controller-runtime/pkg/manager"
2932
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
3033
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
34+
35+
velerov1 "github.com/heptio/velero/pkg/apis/velero/v1"
36+
configv1 "github.com/openshift/api/config/v1"
37+
minterv1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1"
38+
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
3139
)
3240

3341
// Change below variables to serve metrics on different host or port.
@@ -36,7 +44,13 @@ var (
3644
metricsPort int32 = 8383
3745
operatorMetricsPort int32 = 8686
3846
)
39-
var log = logf.Log.WithName("cmd")
47+
48+
var log = logf.Log.WithName(version.OperatorName)
49+
50+
const ManagedVeleroOperatorNamespace = "openshift-velero"
51+
52+
// supportedPlatforms is the list of platform supported by the operator
53+
var supportedPlatforms = []configv1.PlatformType{configv1.AWSPlatformType}
4054

4155
func printVersion() {
4256
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
@@ -67,9 +81,16 @@ func main() {
6781

6882
printVersion()
6983

70-
namespace, err := k8sutil.GetWatchNamespace()
84+
namespace, err := k8sutil.GetOperatorNamespace()
7185
if err != nil {
72-
log.Error(err, "Failed to get watch namespace")
86+
log.Error(err, "Failed to get operator namespace")
87+
os.Exit(1)
88+
}
89+
90+
// The operator makes assumptions about the namespace to configure Velero in.
91+
// If the operator is deployed in a different namespace than expected, error.
92+
if namespace != ManagedVeleroOperatorNamespace {
93+
log.Error(fmt.Errorf("unexpected operator namespace: expected %s, got %s", ManagedVeleroOperatorNamespace, namespace), "")
7394
os.Exit(1)
7495
}
7596

@@ -107,6 +128,49 @@ func main() {
107128
os.Exit(1)
108129
}
109130

131+
// Add Custom Resource apis to scheme
132+
if err := apiextv1beta1.AddToScheme(mgr.GetScheme()); err != nil {
133+
log.Error(err, "")
134+
os.Exit(1)
135+
}
136+
137+
// Add OpenShift config apis to scheme
138+
if err := configv1.Install(mgr.GetScheme()); err != nil {
139+
log.Error(err, "")
140+
os.Exit(1)
141+
}
142+
143+
// Add Cloud Credential apis to scheme
144+
if err := minterv1.AddToScheme(mgr.GetScheme()); err != nil {
145+
log.Error(err, "")
146+
os.Exit(1)
147+
}
148+
149+
// Add Velero apis to scheme
150+
if err := velerov1.SchemeBuilder.AddToScheme(mgr.GetScheme()); err != nil {
151+
log.Error(err, "")
152+
os.Exit(1)
153+
}
154+
155+
// Grab platform status to determine where OpenShift is installed
156+
platformClient, err := crclient.New(cfg, crclient.Options{Scheme: mgr.GetScheme()})
157+
if err != nil {
158+
log.Error(err, "Unable to create platform client")
159+
os.Exit(1)
160+
}
161+
platformStatus, err := platform.GetPlatformStatus(platformClient)
162+
if err != nil {
163+
log.Error(err, "Failed to retrieve platform status")
164+
os.Exit(1)
165+
}
166+
167+
// Verify platform is in support platforms list.
168+
// TODO: expand support to other platforms
169+
if !platform.IsPlatformSupported(platformStatus.Type, supportedPlatforms) {
170+
log.Error(fmt.Errorf("expected %v got %v", supportedPlatforms, platformStatus.Type), "Unsupported platform")
171+
os.Exit(1)
172+
}
173+
110174
// Setup all Controllers
111175
if err := controller.AddToManager(mgr); err != nil {
112176
log.Error(err, "")

deploy/cluster_role.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
creationTimestamp: null
5+
name: managed-velero-operator
6+
namespace: openshift-velero
7+
rules:
8+
- apiGroups:
9+
- apiextensions.k8s.io
10+
resources:
11+
- customresourcedefinitions
12+
verbs:
13+
- '*'
14+
- apiGroups:
15+
- config.openshift.io
16+
resources:
17+
- infrastructures
18+
verbs:
19+
- get
20+
- list
21+
- watch

deploy/cluster_role_binding.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: managed-velero-operator
5+
namespace: openshift-velero
6+
subjects:
7+
- kind: ServiceAccount
8+
name: managed-velero-operator
9+
namespace: openshift-velero
10+
roleRef:
11+
kind: ClusterRole
12+
name: managed-velero-operator
13+
apiGroup: rbac.authorization.k8s.io
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: managed.openshift.io/v1alpha1
2+
kind: Velero
3+
metadata:
4+
name: cluster
5+
namespace: openshift-velero
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: veleros.managed.openshift.io
5+
spec:
6+
additionalPrinterColumns:
7+
- JSONPath: .status.s3Bucket.name
8+
description: Name of the S3 bucket
9+
name: Bucket
10+
type: string
11+
- JSONPath: .status.s3Bucket.provisioned
12+
description: Has the S3 bucket been successfully provisioned
13+
name: Provisioned
14+
type: boolean
15+
- JSONPath: .status.s3Bucket.lastSyncTimestamp
16+
name: Last Sync
17+
type: date
18+
group: managed.openshift.io
19+
names:
20+
kind: Velero
21+
listKind: VeleroList
22+
plural: veleros
23+
singular: velero
24+
scope: Namespaced
25+
subresources:
26+
status: {}
27+
validation:
28+
openAPIV3Schema:
29+
properties:
30+
apiVersion:
31+
description: 'APIVersion defines the versioned schema of this representation
32+
of an object. Servers should convert recognized schemas to the latest
33+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
34+
type: string
35+
kind:
36+
description: 'Kind is a string value representing the REST resource this
37+
object represents. Servers may infer this from the endpoint the client
38+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
39+
type: string
40+
metadata:
41+
type: object
42+
spec:
43+
type: object
44+
status:
45+
properties:
46+
s3Bucket:
47+
description: S3Bucket contains details of the S3 storage bucket for
48+
backups
49+
properties:
50+
lastSyncTimestamp:
51+
description: LastSyncTimestamp is the time that the bucket policy
52+
was last synced.
53+
format: date-time
54+
type: string
55+
name:
56+
description: Name is the name of the S3 bucket created to store
57+
Velero backup details
58+
maxLength: 63
59+
type: string
60+
provisioned:
61+
description: Provisioned is true once the bucket has been initially
62+
provisioned.
63+
type: boolean
64+
required:
65+
- provisioned
66+
type: object
67+
type: object
68+
version: v1alpha1
69+
versions:
70+
- name: v1alpha1
71+
served: true
72+
storage: true

deploy/credential_request.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: cloudcredential.openshift.io/v1
2+
kind: CredentialsRequest
3+
metadata:
4+
name: managed-velero-operator-iam-credentials
5+
namespace: openshift-velero
6+
spec:
7+
secretRef:
8+
name: managed-velero-operator-iam-credentials
9+
namespace: openshift-velero
10+
providerSpec:
11+
apiVersion: cloudcredential.openshift.io/v1
12+
kind: AWSProviderSpec
13+
statementEntries:
14+
- effect: Allow
15+
action:
16+
- s3:CreateBucket
17+
- s3:ListBucket
18+
- s3:PutBucketAcl
19+
- s3:PutBucketPublicAccessBlock
20+
- s3:PutEncryptionConfiguration
21+
- s3:PutLifecycleConfiguration
22+
resource: "*"

deploy/operator.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: managed-velero-operator
5+
namespace: openshift-velero
56
spec:
67
replicas: 1
78
selector:
@@ -21,10 +22,6 @@ spec:
2122
- managed-velero-operator
2223
imagePullPolicy: Always
2324
env:
24-
- name: WATCH_NAMESPACE
25-
valueFrom:
26-
fieldRef:
27-
fieldPath: metadata.namespace
2825
- name: POD_NAME
2926
valueFrom:
3027
fieldRef:

deploy/role.yaml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
kind: Role
21
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
33
metadata:
4+
creationTimestamp: null
45
name: managed-velero-operator
6+
namespace: openshift-velero
57
rules:
68
- apiGroups:
79
- ""
@@ -15,7 +17,7 @@ rules:
1517
- configmaps
1618
- secrets
1719
verbs:
18-
- "*"
20+
- '*'
1921
- apiGroups:
2022
- apps
2123
resources:
@@ -24,22 +26,22 @@ rules:
2426
- replicasets
2527
- statefulsets
2628
verbs:
27-
- "*"
29+
- '*'
2830
- apiGroups:
2931
- monitoring.coreos.com
3032
resources:
3133
- servicemonitors
3234
verbs:
33-
- "get"
34-
- "create"
35+
- get
36+
- create
3537
- apiGroups:
3638
- apps
37-
resources:
38-
- deployments/finalizers
3939
resourceNames:
4040
- managed-velero-operator
41+
resources:
42+
- deployments/finalizers
4143
verbs:
42-
- "update"
44+
- update
4345
- apiGroups:
4446
- ""
4547
resources:
@@ -52,3 +54,23 @@ rules:
5254
- replicasets
5355
verbs:
5456
- get
57+
- apiGroups:
58+
- managed.openshift.io
59+
resources:
60+
- veleros
61+
- veleros/status
62+
- veleros/finalizers
63+
verbs:
64+
- '*'
65+
- apiGroups:
66+
- velero.io
67+
resources:
68+
- '*'
69+
verbs:
70+
- '*'
71+
- apiGroups:
72+
- cloudcredential.openshift.io
73+
resources:
74+
- credentialsrequests
75+
verbs:
76+
- '*'

0 commit comments

Comments
 (0)