Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ generate: get-crds generate-stackgres-crds generate-cnpg-crds protobuf-gen ## G

.PHONY: generate-stackgres-crds
generate-stackgres-crds:
curl ${STACKGRES_CRD_URL}/SGDbOps.yaml?inline=false -o apis/stackgres/v1/sgdbops_crd.yaml
yq -i e apis/stackgres/v1/sgdbops.yaml --expression ".components.schemas.SGDbOpsSpec=load(\"apis/stackgres/v1/sgdbops_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
yq -i e apis/stackgres/v1/sgdbops.yaml --expression ".components.schemas.SGDbOpsStatus=load(\"apis/stackgres/v1/sgdbops_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.status"
go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1 -generate=types -o apis/stackgres/v1/sgdbops.gen.go apis/stackgres/v1/sgdbops.yaml
perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1/sgdbops.gen.go
# curl ${STACKGRES_CRD_URL}/SGDbOps.yaml?inline=false -o apis/stackgres/v1/sgdbops_crd.yaml
# yq -i e apis/stackgres/v1/sgdbops.yaml --expression ".components.schemas.SGDbOpsSpec=load(\"apis/stackgres/v1/sgdbops_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
# yq -i e apis/stackgres/v1/sgdbops.yaml --expression ".components.schemas.SGDbOpsStatus=load(\"apis/stackgres/v1/sgdbops_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.status"
# go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1 -generate=types -o apis/stackgres/v1/sgdbops.gen.go apis/stackgres/v1/sgdbops.yaml
# perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1/sgdbops.gen.go

# curl ${STACKGRES_CRD_URL}/SGCluster.yaml?inline=false -o apis/stackgres/v1/sgcluster_crd.yaml
# yq -i e apis/stackgres/v1/sgcluster.yaml --expression ".components.schemas.SGClusterSpec=load(\"apis/stackgres/v1/sgcluster_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
Expand All @@ -122,15 +122,15 @@ generate-stackgres-crds:
# go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1 -generate=types -o apis/stackgres/v1/sgpoolconfigs.gen.go apis/stackgres/v1/sgpoolconfigs.yaml
# perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1/sgpoolconfigs.gen.go

curl ${STACKGRES_CRD_URL}/SGObjectStorage.yaml?inline=false -o apis/stackgres/v1beta1/sgobjectstorage_crd.yaml
yq -i e apis/stackgres/v1beta1/sgobjectstorage.yaml --expression ".components.schemas.SGObjectStorageSpec=load(\"apis/stackgres/v1beta1/sgobjectstorage_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1beta1 -generate=types -o apis/stackgres/v1beta1/sgobjectstorage.gen.go apis/stackgres/v1beta1/sgobjectstorage.yaml
perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1beta1/sgobjectstorage.gen.go
# curl ${STACKGRES_CRD_URL}/SGObjectStorage.yaml?inline=false -o apis/stackgres/v1beta1/sgobjectstorage_crd.yaml
# yq -i e apis/stackgres/v1beta1/sgobjectstorage.yaml --expression ".components.schemas.SGObjectStorageSpec=load(\"apis/stackgres/v1beta1/sgobjectstorage_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
# go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1beta1 -generate=types -o apis/stackgres/v1beta1/sgobjectstorage.gen.go apis/stackgres/v1beta1/sgobjectstorage.yaml
# perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1beta1/sgobjectstorage.gen.go


go run sigs.k8s.io/controller-tools/cmd/controller-gen object paths=./apis/stackgres/v1/...
go run sigs.k8s.io/controller-tools/cmd/controller-gen object paths=./apis/stackgres/v1beta1/...
rm apis/stackgres/v1/*_crd.yaml
rm -f apis/stackgres/v1/*_crd.yaml
Comment thread
Kidswiss marked this conversation as resolved.

.PHONY: generate-cnpg-crds
generate-cnpg-crds:
Expand Down
10 changes: 10 additions & 0 deletions apis/s3/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build generate

// Remove existing manifests

// Generate deepcopy methodsets and CRD manifests

// Generate crossplane-runtime methodsets (resource.Claim, etc)
//go:generate go run -tags generate github.com/crossplane/crossplane-tools/cmd/angryjet generate-methodsets --header-file=../../.github/boilerplate.go.txt ./...

package s3
111 changes: 111 additions & 0 deletions apis/s3/v1/bucket_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package v1

import (
"reflect"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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

// +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,s3}
// +kubebuilder:webhook:verbs=create;update,path=/validate-s3-crossplane-io-v1-bucket,mutating=false,failurePolicy=fail,groups=s3.crossplane.io,resources=buckets,versions=v1,name=buckets.s3.crossplane.io,sideEffects=None,admissionReviewVersions=v1

type Bucket struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BucketSpec `json:"spec"`
Status BucketStatus `json:"status,omitempty"`
}

type BucketSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider BucketParameters `json:"forProvider,omitempty"`
}

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"`

// Policy is a raw S3 bucket policy.
// Please consult https://min.io/docs/minio/linux/administration/identity-access-management/policy-based-access-control.html for more details about the policy.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointing to this intentionally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still use the minio client internally. So it should still be valid.

Policy *string `json:"policy,omitempty"`
}

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

// +kubebuilder:object:root=true

type BucketList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bucket `json:"items"`
}

// Dummy type metadata.
var (
BucketKind = reflect.TypeOf(Bucket{}).Name()
BucketGroupKind = schema.GroupKind{Group: Group, Kind: BucketKind}.String()
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
}
25 changes: 25 additions & 0 deletions apis/s3/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// +kubebuilder:object:generate=true
// +groupName=s3.crossplane.io
// +versionName=v1

// Package v1 contains the v1 group s3.crossplane.io resources of provider-s3.
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

// Package type metadata.
const (
Group = "s3.crossplane.io"
Version = "v1"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
)
137 changes: 137 additions & 0 deletions apis/s3/v1/zz_generated.deepcopy.go

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

65 changes: 65 additions & 0 deletions apis/s3/v1/zz_generated.managed.go

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

Loading
Loading