Skip to content

Commit

Permalink
Merge pull request #15 from vshn/add/bucket
Browse files Browse the repository at this point in the history
Implement bucket handling
  • Loading branch information
Kidswiss authored Aug 29, 2023
2 parents 062f763 + f5738f2 commit 1fbe956
Show file tree
Hide file tree
Showing 37 changed files with 990 additions and 84 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: E2E

on:
push:
branches:
- master
paths-ignore:
- docs/**
# schedule:
Expand Down Expand Up @@ -34,9 +32,6 @@ jobs:

- name: Run tests
run: make test-e2e
env:
EXOSCALE_API_KEY: ${{ secrets.EXOSCALE_API_KEY }}
EXOSCALE_API_SECRET: ${{ secrets.EXOSCALE_API_SECRET }}

- name: Cleanup
run: make clean
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/provider-minio
*.out
/package/*.xpkg
/package/crossplane.yaml
/kubeconfig

# Docs
/.cache/
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ install-crd: generate ## Install CRDs into cluster
.PHONY: install-samples
install-samples: export KUBECONFIG = $(KIND_KUBECONFIG)
install-samples: ## Install samples into cluster
yq ./samples/exoscale*.yaml | kubectl apply -f -
yq ./samples/minio*.yaml | kubectl apply -f -

.PHONY: delete-samples
delete-samples: export KUBECONFIG = $(KIND_KUBECONFIG)
Expand Down Expand Up @@ -135,4 +135,3 @@ webhook-debug:
# kubectl apply -f - && \
# kubectl annotate validatingwebhookconfigurations.admissionregistration.k8s.io appcat-redis-validation cert-manager.io/inject-ca-from- && \
# kubectl annotate validatingwebhookconfigurations.admissionregistration.k8s.io appcat-pg-validation kubectl.kubernetes.io/last-applied-configuration- && \

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Documentation: https://vshn.github.io/provider-minio/
* `kubectl`
* `yq`
* `sed` (or `gsed` for Mac)
* [kindev](https://github.com/vshn/kindev)

Some other requirements (e.g. `kind`) will be compiled on-the-fly and put in the local cache dir `.kind` as needed.

Expand All @@ -39,9 +38,8 @@ See all targets with `make help`

### QuickStart Demonstration

1. Get an API token exoscale.com
1. TODO: TBD
1. `make local-install`
1. Make sure you have a kind cluster running and the config exported
2. `make local-install`

### Kubernetes Webhook Troubleshooting
TODO: there are currently no webhooks configured.
Expand Down Expand Up @@ -85,4 +83,4 @@ If tests succeed, the relevant resources are deleted to not use up costs on the

### Cleaning up e2e tests

Simply delete the whole kindev cluster.
`make clean`
54 changes: 52 additions & 2 deletions apis/minio/v1/bucket_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,38 @@ import (

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

func init() {
SchemeBuilder.Register(&Bucket{}, &BucketList{})
}

const (
// DeleteIfEmpty only deletes the bucket if the bucket is empty.
DeleteIfEmpty BucketDeletionPolicy = "DeleteIfEmpty"
// DeleteAll recursively deletes all objects in the bucket and then removes it.
DeleteAll BucketDeletionPolicy = "DeleteAll"
)

// BucketDeletionPolicy determines how buckets should be deleted when a Bucket is deleted.
type BucketDeletionPolicy string

// We can't have this here, because ironically the generator breaks if this throws and error...
// var _ resource.Managed = &Bucket{}
var _ runtime.Object = &Bucket{}
// var _ runtime.Object = &Bucket{}

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="Synced",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="External Name",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".status.endpointURL"
// +kubebuilder:printcolumn:name="Bucket Name",type="string",JSONPath=".status.atProvider.bucketName"
// +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".spec.forProvider.region"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,minio}
// +kubebuilder:webhook:verbs=create;update,path=/validate-minio-crossplane-io-v1-bucket,mutating=false,failurePolicy=fail,groups=minio.crossplane.io,resources=buckets,versions=v1,name=buckets.minio.crossplane.io,sideEffects=None,admissionReviewVersions=v1

type Bucket struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -35,13 +53,37 @@ type BucketSpec struct {

type BucketStatus struct {
xpv1.ResourceStatus `json:",inline"`
Endpoint string `json:"endpoint,omitempty"`
EndpointURL string `json:"endpointURL,omitempty"`
AtProvider BucketProviderStatus `json:"atProvider,omitempty"`
}

type BucketParameters struct {
// BucketName is the name of the bucket to create.
// Defaults to `metadata.name` if unset.
// Cannot be changed after bucket is created.
// Name must be acceptable by the S3 protocol, which follows RFC 1123.
// Be aware that S3 providers may require a unique name across the platform or zone.
BucketName string `json:"bucketName,omitempty"`

// +kubebuilder:validation:Required
// +kubebuilder:default="us-east-1"

// Region is the name of the region where the bucket shall be created.
// The region must be available in the S3 endpoint.
// Cannot be changed after bucket is created.
Region string `json:"region,omitempty"`

// BucketDeletionPolicy determines how buckets should be deleted when Bucket is deleted.
// `DeleteIfEmpty` only deletes the bucket if the bucket is empty.
// `DeleteAll` recursively deletes all objects in the bucket and then removes it.
// To skip deletion of the bucket (orphan it) set `spec.deletionPolicy=Orphan`.
BucketDeletionPolicy BucketDeletionPolicy `json:"bucketDeletionPolicy,omitempty"`
}

type BucketProviderStatus struct {
// BucketName is the name of the actual bucket.
BucketName string `json:"bucketName,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -59,3 +101,11 @@ var (
BucketKindAPIVersion = BucketKind + "." + SchemeGroupVersion.String()
BucketGroupVersionKind = SchemeGroupVersion.WithKind(BucketKind)
)

// GetBucketName returns the spec.forProvider.bucketName if given, otherwise defaults to metadata.name.
func (in *Bucket) GetBucketName() string {
if in.Spec.ForProvider.BucketName == "" {
return in.Name
}
return in.Spec.ForProvider.BucketName
}
2 changes: 1 addition & 1 deletion apis/minio/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion apis/provider/v1/providerconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import (
type ProviderConfigSpec struct {
// Credentials required to authenticate to this provider.
Credentials ProviderCredentials `json:"credentials"`
// +kubebuilder:validation:Required
// MinioURL is where the Minio instance that should be managed is located.
MinioURL string `json:"minioURL,omitempty"`
}

// ProviderCredentials required to authenticate.
type ProviderCredentials struct {
//+kubebuilder:validation:Enum=None;Secret;InjectedIdentity;Environment;Filesystem

// Source represents location of the cluster token.
Source xpv1.CredentialsSource `json:"source"`
Source xpv1.CredentialsSource `json:"source,omitempty"`

// APISecretRef is the reference to the secret with the minio API Key and Secret.
APISecretRef corev1.SecretReference `json:"apiSecretRef,omitempty"`
Expand Down
35 changes: 32 additions & 3 deletions generate_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/vshn/provider-minio/apis"
miniov1 "github.com/vshn/provider-minio/apis/minio/v1"
providerv1 "github.com/vshn/provider-minio/apis/provider/v1"
"github.com/vshn/provider-minio/operator/minioutil"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -27,12 +28,15 @@ import (
serializerjson "k8s.io/apimachinery/pkg/runtime/serializer/json"
)

var scheme = runtime.NewScheme()
var (
scheme = runtime.NewScheme()
)

func main() {
failIfError(apis.AddToScheme(scheme))
generateBucketSample()
generateProviderConfigSample()
generateSecretSample()
}

func generateBucketSample() {
Expand All @@ -51,7 +55,9 @@ func newBucketSample() *miniov1.Bucket {
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{Name: "provider-config"},
},
ForProvider: miniov1.BucketParameters{},
ForProvider: miniov1.BucketParameters{
Region: "us-east-1",
},
},
}
}
Expand All @@ -70,17 +76,40 @@ func newProviderConfigSample() *providerv1.ProviderConfig {
ObjectMeta: metav1.ObjectMeta{
Name: "provider-config"},
Spec: providerv1.ProviderConfigSpec{
MinioURL: "http://minio.127.0.0.1.nip.io:8088/",
Credentials: providerv1.ProviderCredentials{
Source: xpv1.CredentialsSourceInjectedIdentity,
APISecretRef: corev1.SecretReference{
Name: "api-secret",
Name: "minio-secret",
Namespace: "crossplane-system",
},
},
},
}
}

func generateSecretSample() {
spec := newSecretSample()
serialize(spec, true)
}

func newSecretSample() *corev1.Secret {
return &corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
ObjectMeta: metav1.ObjectMeta{
Name: "minio-secret",
Namespace: "crossplane-system",
},
Data: map[string][]byte{
minioutil.MinioIDKey: []byte("minioadmin"),
minioutil.MinioSecretKey: []byte("minioadmin"),
},
}
}

func failIfError(err error) {
if err != nil {
log.Fatal(err)
Expand Down
20 changes: 16 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ require (
github.com/crossplane/crossplane-tools v0.0.0-20230714144037-2684f4bc7638
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.4
github.com/minio/minio-go/v7 v7.0.62
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.25.7
go.uber.org/zap v1.25.0
k8s.io/api v0.28.0
Expand All @@ -25,6 +28,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/dave/jennifer v1.4.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.15.0 // indirect
Expand All @@ -44,37 +48,45 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.0 // indirect
Expand Down
Loading

0 comments on commit 1fbe956

Please sign in to comment.