Skip to content

Commit 7114c79

Browse files
authored
Merge pull request #1 from pluralsh/init
initial commit
2 parents 6b1b81d + a138303 commit 7114c79

21 files changed

+1426
-0
lines changed

Makefile

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= database-interface:latest
4+
5+
CRD_OPTIONS ?= "crd"
6+
7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
14+
all: build
15+
16+
##@ General
17+
18+
# The help target prints out all targets with their descriptions organized
19+
# beneath their categories. The categories are represented by '##@' and the
20+
# target descriptions by '##'. The awk commands is responsible for reading the
21+
# entire set of makefiles included in this invocation, looking for lines of the
22+
# file as xyz: ## something, and then pretty-format the target and help. Then,
23+
# if there's a line with ##@ something, that gets pretty-printed as a category.
24+
# More info on the usage of ANSI control characters for terminal formatting:
25+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
26+
# More info on the awk command:
27+
# http://linuxcommand.org/lc3_adv_awk.php
28+
29+
help: ## Display this help.
30+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
31+
32+
##@ Development
33+
34+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
35+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
36+
37+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
38+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
39+
40+
fmt: ## Run go fmt against code.
41+
go fmt ./...
42+
43+
vet: ## Run go vet against code.
44+
go vet ./...
45+
46+
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
47+
test: manifests generate fmt vet ## Run tests.
48+
mkdir -p ${ENVTEST_ASSETS_DIR}
49+
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
50+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
51+
52+
unit-test:
53+
go test -tags=unit -v -race ./controllers/...
54+
55+
##@ Build
56+
57+
build: generate fmt vet ## Build manager binary.
58+
go build -o bin/manager main.go
59+
60+
run: manifests generate fmt vet ## Run a controller from your host.
61+
ENABLE_WEBHOOKS=false go run ./main.go -zap-log-level 2
62+
63+
docker-build: build ## Build docker image with the manager.
64+
docker build -t ${IMG} .
65+
66+
docker-push: ## Push docker image with the manager.
67+
docker push ${IMG}
68+
69+
##@ Deployment
70+
71+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
72+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
73+
74+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
75+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
76+
77+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
78+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
79+
$(KUSTOMIZE) build config/default | kubectl apply -f -
80+
81+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
82+
$(KUSTOMIZE) build config/default | kubectl delete -f -
83+
84+
85+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
86+
controller-gen: ## Download controller-gen locally if necessary.
87+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
88+
89+
KUSTOMIZE = $(shell pwd)/bin/kustomize
90+
kustomize: ## Download kustomize locally if necessary.
91+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
92+
93+
client-gen:
94+
./hack/update-codegen.sh
95+
mv github.com/pluralsh/plural-operator/generated generated
96+
rm -rf github.com
97+
98+
# go-get-tool will 'go get' any package $2 and install it to $1.
99+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
100+
define go-get-tool
101+
@[ -f $(1) ] || { \
102+
set -e ;\
103+
TMP_DIR=$$(mktemp -d) ;\
104+
cd $$TMP_DIR ;\
105+
go mod init tmp ;\
106+
echo "Downloading $(2)" ;\
107+
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
108+
rm -rf $$TMP_DIR ;\
109+
}
110+
endef

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Database Interface API
2+
3+
This repository hosts the API defintion of the Custom Resource Definitions (CRD) used for the Database Interface project.
4+
The provisioned unit of storage is a `Database`. The following CRDs are defined for managing the lifecycle of Databases:
5+
6+
- DatabaseRequest - Represents a request to provision a Database
7+
- DatabaseClass - Represents a class of Datbase with similar characteristics
8+
- Database - Represents a Database
9+
10+
The following CRDs are defined for managing the lifecycle of workloads accessing the Database:
11+
12+
- DatabaseAccessClass - Represents a class of accessors with similar access requirements
13+
- DatabaseAccess - Represents an access secret to the Database
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright 2022.
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+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
func init() {
25+
SchemeBuilder.Register(&Database{}, &DatabaseList{})
26+
}
27+
28+
type DatabaseSpec struct {
29+
// DriverName is the name of driver associated with this database
30+
DriverName string `json:"driverName"`
31+
32+
// Name of the DatabaseClass specified in the DatabaseRequest
33+
DatabaseClassName string `json:"databaseClassName"`
34+
35+
// Name of the DatabaseRequest that resulted in the creation of this Database
36+
// In case the Database object was created manually, then this should refer
37+
// to the DatabaseRequest with which this Database should be bound
38+
DatabaseRequest *corev1.ObjectReference `json:"databaseRequest"`
39+
40+
// +optional
41+
Parameters map[string]string `json:"parameters,omitempty"`
42+
43+
// ExistingDatabaseID is the unique id of the database.
44+
// This field will be empty when the Database is dynamically provisioned by operator.
45+
// +optional
46+
ExistingDatabaseID string `json:"existingBucketID,omitempty"`
47+
}
48+
49+
type DatabaseStatus struct {
50+
// Ready is a boolean condition to reflect the successful creation
51+
// of a database.
52+
Ready bool `json:"ready,omitempty"`
53+
54+
// DatabaseID is the unique id of the database
55+
// +optional
56+
DatabaseID string `json:"databaseID,omitempty"`
57+
}
58+
59+
// +kubebuilder:object:root=true
60+
// +kubebuilder:resource:scope=Cluster
61+
// +kubebuilder:subresource:status
62+
type Database struct {
63+
metav1.TypeMeta `json:",inline"`
64+
// +optional
65+
66+
metav1.ObjectMeta `json:"metadata,omitempty"`
67+
68+
Spec DatabaseSpec `json:"spec,omitempty"`
69+
70+
// +optional
71+
Status DatabaseStatus `json:"status,omitempty"`
72+
}
73+
74+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
75+
76+
type DatabaseList struct {
77+
metav1.TypeMeta `json:",inline"`
78+
metav1.ListMeta `json:"metadata,omitempty"`
79+
Items []Database `json:"items"`
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2022.
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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
21+
func init() {
22+
SchemeBuilder.Register(&DatabaseAccess{}, &DatabaseAccessList{})
23+
}
24+
25+
type DatabaseAccessSpec struct {
26+
// DatabaseRequestName is the name of the DatabaseRequest.
27+
DatabaseRequestName string `json:"databaseRequestName"`
28+
29+
// DatabaseAccessClassName is the name of the DatabaseAccessClass
30+
DatabaseAccessClassName string `json:"bucketAccessClassName"`
31+
32+
// CredentialsSecretName is the name of the secret that operator should populate
33+
// with the credentials. If a secret by this name already exists, then it is
34+
// assumed that credentials have already been generated. It is not overridden.
35+
// This secret is deleted when the DatabaseAccess is delted.
36+
CredentialsSecretName string `json:"credentialsSecretName"`
37+
}
38+
39+
type DatabaseAccessStatus struct {
40+
// AccountID is the unique ID for the account in the OSP. It will be populated
41+
// by the COSI sidecar once access has been successfully granted.
42+
// +optional
43+
AccountID string `json:"accountID,omitempty"`
44+
45+
// AccessGranted indicates the successful grant of privileges to access the bucket
46+
// +optional
47+
AccessGranted bool `json:"accessGranted"`
48+
}
49+
50+
// +kubebuilder:object:root=true
51+
// +kubebuilder:resource:scope=Namespaced
52+
// +kubebuilder:subresource:status
53+
type DatabaseAccess struct {
54+
metav1.TypeMeta `json:",inline"`
55+
56+
// +optional
57+
metav1.ObjectMeta `json:"metadata,omitempty"`
58+
59+
Spec DatabaseAccessSpec `json:"spec,omitempty"`
60+
61+
// +optional
62+
Status DatabaseAccessStatus `json:"status"`
63+
}
64+
65+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
66+
67+
type DatabaseAccessList struct {
68+
metav1.TypeMeta `json:",inline"`
69+
metav1.ListMeta `json:"metadata,omitempty"`
70+
Items []DatabaseAccess `json:"items"`
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright 2022.
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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
21+
func init() {
22+
SchemeBuilder.Register(&DatabaseClass{}, &DatabaseClassList{})
23+
SchemeBuilder.Register(&DatabaseAccessClass{}, &DatabaseAccessClassList{})
24+
}
25+
26+
type AuthenticationType string
27+
28+
// +kubebuilder:object:root=true
29+
// +kubebuilder:resource:scope=Cluster
30+
type DatabaseClass struct {
31+
metav1.TypeMeta `json:",inline"`
32+
33+
// +optional
34+
metav1.ObjectMeta `json:"metadata,omitempty"`
35+
36+
// DriverName is the name of driver associated with this database
37+
DriverName string `json:"driverName"`
38+
39+
// Parameters is an opaque map for passing in configuration to a driver
40+
// for creating the bucket
41+
// +optional
42+
Parameters map[string]string `json:"parameters,omitempty"`
43+
}
44+
45+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
46+
47+
type DatabaseClassList struct {
48+
metav1.TypeMeta `json:",inline"`
49+
metav1.ListMeta `json:"metadata,omitempty"`
50+
Items []DatabaseClass `json:"items"`
51+
}
52+
53+
// +kubebuilder:object:root=true
54+
// +kubebuilder:resource:scope=Cluster
55+
type DatabaseAccessClass struct {
56+
metav1.TypeMeta `json:",inline"`
57+
58+
// +optional
59+
metav1.ObjectMeta `json:"metadata,omitempty"`
60+
61+
// DriverName is the name of driver associated with
62+
// this DatabaseAccess
63+
DriverName string `json:"driverName"`
64+
65+
// AuthenticationType denotes the style of authentication
66+
AuthenticationType AuthenticationType `json:"authenticationType"`
67+
68+
// Parameters is an opaque map for passing in configuration to a driver
69+
// for granting access to a bucket
70+
// +optional
71+
Parameters map[string]string `json:"parameters,omitempty"`
72+
}
73+
74+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
75+
76+
type DatabaseAccessClassList struct {
77+
metav1.TypeMeta `json:",inline"`
78+
metav1.ListMeta `json:"metadata,omitempty"`
79+
Items []DatabaseAccessClass `json:"items"`
80+
}

0 commit comments

Comments
 (0)