Skip to content

Commit 34b85b3

Browse files
Eneman DonatienEneman Donatien
authored andcommitted
implement mulittenancy
1 parent d24b8a2 commit 34b85b3

28 files changed

+1149
-107
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ RUN go mod download
1515
COPY main.go main.go
1616
COPY api/ api/
1717
COPY controllers/ controllers/
18+
COPY internal/ internal/
19+
1820

1921
# Build
2022
# the GOARCH has not a default value to allow the binary be built according to the host where the command

README.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This Operator SDK based tool aims at managing S3 related resources (buckets, pol
44

55
## At a glance
66

7-
- Current S3 providers : [Minio](https://github.com/InseeFrLab/s3-operator/blob/main/controllers/s3/factory/minioS3Client.go)
7+
- Current S3 providers : [Minio](https://github.com/InseeFrLab/s3-operator/blob/main/internal/s3/factory/minioS3Client.go)
88
- Currently managed S3 resources : [buckets](https://github.com/InseeFrLab/s3-operator/blob/main/api/v1alpha1/bucket_types.go), [policies](https://github.com/InseeFrLab/s3-operator/blob/main/api/v1alpha1/policy_types.go)
99

1010
## Compatibility
@@ -21,14 +21,16 @@ At its heart, the operator revolves around CRDs that match S3 resources :
2121
- `buckets.s3.onyxia.sh`
2222
- `policies.s3.onyxia.sh`
2323
- `paths.s3.onyxia.sh`
24-
- `users.s3.onyxia.sh`
24+
- `s3Users.s3.onyxia.sh`
25+
- `s3Instances.s3.onyxia.sh`
2526

2627
The custom resources based on these CRDs are a somewhat simplified projection of the real S3 resources. From the operator's point of view :
2728

2829
- A `Bucket` CR matches a S3 bucket, and only has a name, a quota (actually two, [see Bucket example in *Usage* section below](#bucket)), and optionally, a set of paths
2930
- A `Policy` CR matches a "canned" policy (not a bucket policy, but a global one, that can be attached to a user), and has a name, and its actual content (IAM JSON)
3031
- A `Path` CR matches a set of paths inside of a policy. This is akin to the `paths` property of the `Bucket` CRD, except `Path` is not responsible for Bucket creation.
3132
- A `S3User` CR matches a user in the s3 server, and has a name, a set of policy and a set of group.
33+
- A `S3Instance` CR matches a s3Instance.
3234

3335
Each custom resource based on these CRDs on Kubernetes is to be matched with a resource on the S3 instance. If the CR and the corresponding S3 resource diverge, the operator will create or update the S3 resource to bring it back to.
3436

@@ -90,7 +92,7 @@ The parameters are summarized in the table below :
9092
| `path-deletion` | false | - | no | Trigger path deletion on the S3 backend upon CR deletion. Limited to deleting the `.keep` files used by the operator. |
9193
| `s3User-deletion` | false | - | no | Trigger S3User deletion on the S3 backend upon CR deletion. |
9294
| `override-existing-secret` | false | - | no | Update secret linked to s3User if already exist, else noop |
93-
95+
| `s3LabelSelector` | "" | - | no | Filter resource that this instance will manage. If Empty all resource in the cluster will be manage |
9496
## Minimal rights needed to work
9597

9698
The Operator need at least this rights:
@@ -147,6 +149,29 @@ The Operator need at least this rights:
147149
- The same will happen if you modify a CR - the operator will adjust the S3 bucket or policy accordingly - with the notable exception that it will not delete paths for buckets.
148150
- Upon deleting a CR, the corresponding bucket or policy will be left as is, as mentioned in the [*Description* section above](#description)
149151

152+
An instance of S3Operator can manage multiple S3. On each resource created you can set where to create it. To add multiple instance of S3 see S3Instance example. On each object deployed you can attach it to an existing s3Instance. If no instance is set on the resource, S3Operator will failback to default instance configured by env var.
153+
154+
### S3Instance example
155+
156+
```yaml
157+
apiVersion: s3.onyxia.sh/v1alpha1
158+
kind: S3Instance
159+
metadata:
160+
labels:
161+
app.kubernetes.io/name: bucket
162+
app.kubernetes.io/instance: bucket-sample
163+
app.kubernetes.io/part-of: s3-operator
164+
app.kubernetes.io/managed-by: kustomize
165+
app.kubernetes.io/created-by: s3-operator
166+
name: s3-default-instance # Name of the S3Instance
167+
spec:
168+
s3Provider: minio # Type of the Provider. Can be "mockedS3Provider" or "minio"
169+
urlEndpoint: minio.example.com # URL of the Provider
170+
secretName: minio-credentials # Name of the secret containing 2 Keys S3_ACCESS_KEY and S3_SECRET_KEY
171+
region: us-east-1 # Region of the Provider
172+
useSSL: true # useSSL to query the Provider
173+
```
174+
150175
### Bucket example
151176
152177
```yaml
@@ -182,6 +207,10 @@ spec:
182207
quota:
183208
default: 10000000
184209
# override: 20000000
210+
211+
# Optionnal, let empty if you have configured the default s3 else use an existing s3Instance
212+
s3InstanceRef: "s3-default-instance"
213+
185214

186215
```
187216

@@ -202,6 +231,9 @@ spec:
202231
# Policy name (on S3 server, as opposed to the name of the CR)
203232
name: dummy-policy
204233

234+
# Optionnal, let empty if you have configured the default s3 else use an existing s3Instance
235+
s3InstanceRef: "s3-default-instance"
236+
205237
# Content of the policy, as a multiline string
206238
# This should be IAM compliant JSON - follow the guidelines of the actual
207239
# S3 provider you're using, as sometimes only a subset is available.
@@ -245,6 +277,8 @@ spec:
245277
- /home/alice
246278
- /home/bob
247279

280+
# Optionnal, let empty if you have configured the default s3 else use an existing s3Instance
281+
s3InstanceRef: "s3-default-instance"
248282

249283
```
250284

@@ -266,6 +300,8 @@ spec:
266300
policies:
267301
- policy-example1
268302
- policy-example2
303+
# Optionnal, let empty if you have configured the default s3 else use an existing s3Instance
304+
s3InstanceRef: "s3-default-instance"
269305

270306
```
271307

api/v1alpha1/bucket_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ type BucketSpec struct {
3636
// +kubebuilder:validation:Optional
3737
Paths []string `json:"paths,omitempty"`
3838

39+
// s3InstanceRef where create the bucket
40+
// +kubebuilder:validation:Optional
41+
S3InstanceRef string `json:"s3InstanceRef,omitempty"`
42+
3943
// Quota to apply to the bucket
4044
// +kubebuilder:validation:Required
4145
Quota Quota `json:"quota"`
4246
}
4347

4448
// BucketStatus defines the observed state of Bucket
4549
type BucketStatus struct {
46-
// Status management using Conditions.
50+
// Status management using Conditions.
4751
// See also : https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
4852
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
4953
}

api/v1alpha1/path_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ type PathSpec struct {
3535
// Paths (folders) to create inside the bucket
3636
// +kubebuilder:validation:Optional
3737
Paths []string `json:"paths,omitempty"`
38+
39+
// s3InstanceRef where create the Paths
40+
// +kubebuilder:validation:Optional
41+
S3InstanceRef string `json:"s3InstanceRef,omitempty"`
3842
}
3943

4044
// PathStatus defines the observed state of Path

api/v1alpha1/policy_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ type PolicySpec struct {
3535
// +kubebuilder:validation:Required
3636
// Content of the policy (IAM JSON format)
3737
PolicyContent string `json:"policyContent"`
38+
39+
// s3InstanceRef where create the Policy
40+
// +kubebuilder:validation:Optional
41+
S3InstanceRef string `json:"s3InstanceRef,omitempty"`
3842
}
3943

4044
// PolicyStatus defines the observed state of Policy
4145
type PolicyStatus struct {
42-
// Status management using Conditions.
46+
// Status management using Conditions.
4347
// See also : https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
4448
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
4549
}

api/v1alpha1/s3instance_types.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// S3InstanceSpec defines the desired state of S3Instance
27+
type S3InstanceSpec struct {
28+
29+
// type of the S3Instance
30+
// +kubebuilder:validation:Required
31+
S3Provider string `json:"s3Provider"`
32+
33+
// url of the S3Instance
34+
// +kubebuilder:validation:Required
35+
UrlEndpoint string `json:"urlEndpoint"`
36+
37+
// SecretName associated to the S3Instance containing accessKey and secretKey
38+
// +kubebuilder:validation:Required
39+
SecretName string `json:"secretName"`
40+
41+
// region associated to the S3Instance
42+
// +kubebuilder:validation:Required
43+
Region string `json:"region"`
44+
45+
// useSSL when connecting to the S3Instance
46+
// +kubebuilder:validation:Optional
47+
UseSSL bool `json:"useSSL,omitempty"`
48+
49+
// CaCertificatesBase64 associated to the S3InstanceUrl
50+
// +kubebuilder:validation:Optional
51+
CaCertificatesBase64 []string `json:"caCertificateBase64,omitempty"`
52+
}
53+
54+
// S3InstanceStatus defines the observed state of S3Instance
55+
type S3InstanceStatus struct {
56+
// Status management using Conditions.
57+
// See also : https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
58+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
59+
}
60+
61+
//+kubebuilder:object:root=true
62+
//+kubebuilder:subresource:status
63+
64+
// S3Instance is the Schema for the S3Instances API
65+
type S3Instance struct {
66+
metav1.TypeMeta `json:",inline"`
67+
metav1.ObjectMeta `json:"metadata,omitempty"`
68+
69+
Spec S3InstanceSpec `json:"spec,omitempty"`
70+
Status S3InstanceStatus `json:"status,omitempty"`
71+
}
72+
73+
//+kubebuilder:object:root=true
74+
75+
// S3InstanceList contains a list of S3Instance
76+
type S3InstanceList struct {
77+
metav1.TypeMeta `json:",inline"`
78+
metav1.ListMeta `json:"metadata,omitempty"`
79+
Items []S3Instance `json:"items"`
80+
}
81+
82+
func init() {
83+
SchemeBuilder.Register(&S3Instance{}, &S3InstanceList{})
84+
}

api/v1alpha1/s3user_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type S3UserSpec struct {
3737
// SecretName associated to the S3User
3838
// +kubebuilder:validation:Optional
3939
SecretName string `json:"secretName"`
40+
41+
// s3InstanceRef where create the user
42+
// +kubebuilder:validation:Optional
43+
S3InstanceRef string `json:"s3InstanceRef,omitempty"`
4044
}
4145

4246
// S3UserStatus defines the observed state of S3User

api/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/s3.onyxia.sh_buckets.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ spec:
5757
required:
5858
- default
5959
type: object
60+
s3InstanceRef:
61+
description: s3InstanceRef where create the bucket
62+
type: string
6063
required:
6164
- name
6265
- quota

config/crd/bases/s3.onyxia.sh_paths.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ spec:
4343
items:
4444
type: string
4545
type: array
46+
s3InstanceRef:
47+
description: s3InstanceRef where create the Paths
48+
type: string
4649
required:
4750
- bucketName
4851
type: object

0 commit comments

Comments
 (0)