Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Nov 28, 2024
1 parent f02fd78 commit c1c7e2d
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 22 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
.env
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DEFAULT_S3_ENDPOINT=
DEFAULT_S3_ACCESS_KEY=
DEFAULT_S3_SECRET_KEY=
DEFAULT_S3_REGION=us-east-1
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ go.work

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~

# Environments
.env
.env.testing
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/main.go",
"envFile": "${workspaceFolder}/.env",
"preLaunchTask": "install"
}
]
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "install",
"command": "make",
"args": ["manifests", "kustomize", "install"]
},
{
"label": "build-push",
"command": "make",
"args": ["docker-build", "docker-push", "IMG=tarteo/s3-operator:1.0.0"]
}
]
}
40 changes: 37 additions & 3 deletions api/v1/bucket_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,68 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// +kubebuilder:validation:Enum=Always;OnlyIfEmpty;Preserve
type DeletionPolicy string

const (
Always DeletionPolicy = "Always"
OnlyIfEmpty DeletionPolicy = "OnlyIfEmpty"
Preserve DeletionPolicy = "Preserve"
)

// BucketSpec defines the desired state of Bucket.
type BucketSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Name is immutable"
// Name of the bucket
Name string `json:"name"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Region is immutable"
// +optional
Region string `json:"region"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Secret is immutable"
// +optional
// Name of the secret contains the access and secret key
Secret string `json:"secret"`
Secret string `json:"secret,omitempty"`

// +kubebuilder:default:="accessKey"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="AccessKey is immutable"
// +kubebuilder:validation:Immutable=true
// +optional
// The key in the secret that contains the S3 access key
AccessKey string `json:"accessKey"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="SecretKey is immutable"
// +kubebuilder:default:="secretKey"
// +optional
// The key in the secret that contains the S3 secret key
SecretKey string `json:"secretKey"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="EndpointKey is immutable"
// +kubebuilder:default:="endpointKey"
// +optional
// The key in the secret that contains the endpoint
EndpointKey string `json:"endpointKey"`

// What supposed to happen with the bucket if the resource is deleted
// Valid values are:
// - "Always" (default): Deletes the bucket even if it contains objects;
// - "OnlyIfEmpty": Only delete bucket if is has no objects
// - "Preserve": Never delete the bucket
// +kubebuilder:default:="Always"
// +optional
DeletionPolicy DeletionPolicy `json:"deletionPolicy"`
}

// BucketStatus defines the observed state of Bucket.
type BucketStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

Available bool `json:"available"`
Available bool `json:"available"`
Hash string `json:"hash"`
}

// +kubebuilder:object:root=true
Expand Down
42 changes: 40 additions & 2 deletions config/crd/bases/s3.onestein.nl_buckets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,68 @@ spec:
description: BucketSpec defines the desired state of Bucket.
properties:
accessKey:
default: accessKey
description: The key in the secret that contains the S3 access key
type: string
x-kubernetes-validations:
- message: AccessKey is immutable
rule: self == oldSelf
deletionPolicy:
default: Always
description: |-
What supposed to happen with the bucket if the resource is deleted
Valid values are:
- "Always" (default): Deletes the bucket even if it contains objects;
- "OnlyIfEmpty": Only delete bucket if is has no objects
- "Preserve": Never delete the bucket
enum:
- Always
- OnlyIfEmpty
- Preserve
type: string
endpointKey:
default: endpointKey
description: The key in the secret that contains the endpoint
type: string
x-kubernetes-validations:
- message: EndpointKey is immutable
rule: self == oldSelf
name:
description: Name of the bucket
type: string
x-kubernetes-validations:
- message: Name is immutable
rule: self == oldSelf
region:
type: string
x-kubernetes-validations:
- message: Region is immutable
rule: self == oldSelf
secret:
description: Name of the secret contains the access and secret key
type: string
x-kubernetes-validations:
- message: Secret is immutable
rule: self == oldSelf
secretKey:
default: secretKey
description: The key in the secret that contains the S3 secret key
type: string
x-kubernetes-validations:
- message: SecretKey is immutable
rule: self == oldSelf
required:
- name
- secret
type: object
status:
description: BucketStatus defines the observed state of Bucket.
properties:
available:
type: boolean
hash:
type: string
required:
- available
- hash
type: object
type: object
served: true
Expand Down
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: tarteo/s3-operator
newTag: 1.0.0
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ spec:
- --leader-elect
- --health-probe-bind-address=:8081
image: controller:latest
imagePullPolicy: Always
name: manager
securityContext:
allowPrivilegeEscalation: false
Expand Down
31 changes: 23 additions & 8 deletions config/samples/s3_v1_bucket.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
apiVersion: v1
kind: Secret
apiVersion: s3.onestein.nl/v1
kind: Bucket
metadata:
name: mysecret
type: Opaque
data:
password: <Password>
labels:
app.kubernetes.io/name: s3-operator
app.kubernetes.io/managed-by: kustomize
name: bucket-sample
spec:
name: s3-operator-test-bucket
deletionPolicy: Always
---
apiVersion: s3.onestein.nl/v1
kind: Bucket
metadata:
labels:
app.kubernetes.io/name: s3-operator
app.kubernetes.io/managed-by: kustomize
name: bucket-sample
name: bucket-sample-same-name
spec:
name: s3-operator-test-bucket
deletionPolicy: Always
---
apiVersion: s3.onestein.nl/v1
kind: Bucket
metadata:
labels:
app.kubernetes.io/name: s3-operator
app.kubernetes.io/managed-by: kustomize
name: bucket-sample-preserve
spec:

name: s3-operator-test-bucket-preserve
deletionPolicy: Preserve
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
require (
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand Down Expand Up @@ -42,6 +43,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
Expand Down Expand Up @@ -70,6 +72,9 @@ github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down
Loading

0 comments on commit c1c7e2d

Please sign in to comment.