-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pluralsh/init
initial commit
- Loading branch information
Showing
21 changed files
with
1,426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= database-interface:latest | ||
|
||
CRD_OPTIONS ?= "crd" | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
all: build | ||
|
||
##@ General | ||
|
||
# The help target prints out all targets with their descriptions organized | ||
# beneath their categories. The categories are represented by '##@' and the | ||
# target descriptions by '##'. The awk commands is responsible for reading the | ||
# entire set of makefiles included in this invocation, looking for lines of the | ||
# file as xyz: ## something, and then pretty-format the target and help. Then, | ||
# if there's a line with ##@ something, that gets pretty-printed as a category. | ||
# More info on the usage of ANSI control characters for terminal formatting: | ||
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters | ||
# More info on the awk command: | ||
# http://linuxcommand.org/lc3_adv_awk.php | ||
|
||
help: ## Display this help. | ||
@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) | ||
|
||
##@ Development | ||
|
||
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
fmt: ## Run go fmt against code. | ||
go fmt ./... | ||
|
||
vet: ## Run go vet against code. | ||
go vet ./... | ||
|
||
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin | ||
test: manifests generate fmt vet ## Run tests. | ||
mkdir -p ${ENVTEST_ASSETS_DIR} | ||
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 | ||
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out | ||
|
||
unit-test: | ||
go test -tags=unit -v -race ./controllers/... | ||
|
||
##@ Build | ||
|
||
build: generate fmt vet ## Build manager binary. | ||
go build -o bin/manager main.go | ||
|
||
run: manifests generate fmt vet ## Run a controller from your host. | ||
ENABLE_WEBHOOKS=false go run ./main.go -zap-log-level 2 | ||
|
||
docker-build: build ## Build docker image with the manager. | ||
docker build -t ${IMG} . | ||
|
||
docker-push: ## Push docker image with the manager. | ||
docker push ${IMG} | ||
|
||
##@ Deployment | ||
|
||
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. | ||
$(KUSTOMIZE) build config/default | kubectl delete -f - | ||
|
||
|
||
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
|
||
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
|
||
client-gen: | ||
./hack/update-codegen.sh | ||
mv github.com/pluralsh/plural-operator/generated generated | ||
rm -rf github.com | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Database Interface API | ||
|
||
This repository hosts the API defintion of the Custom Resource Definitions (CRD) used for the Database Interface project. | ||
The provisioned unit of storage is a `Database`. The following CRDs are defined for managing the lifecycle of Databases: | ||
|
||
- DatabaseRequest - Represents a request to provision a Database | ||
- DatabaseClass - Represents a class of Datbase with similar characteristics | ||
- Database - Represents a Database | ||
|
||
The following CRDs are defined for managing the lifecycle of workloads accessing the Database: | ||
|
||
- DatabaseAccessClass - Represents a class of accessors with similar access requirements | ||
- DatabaseAccess - Represents an access secret to the Database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func init() { | ||
SchemeBuilder.Register(&Database{}, &DatabaseList{}) | ||
} | ||
|
||
type DatabaseSpec struct { | ||
// DriverName is the name of driver associated with this database | ||
DriverName string `json:"driverName"` | ||
|
||
// Name of the DatabaseClass specified in the DatabaseRequest | ||
DatabaseClassName string `json:"databaseClassName"` | ||
|
||
// Name of the DatabaseRequest that resulted in the creation of this Database | ||
// In case the Database object was created manually, then this should refer | ||
// to the DatabaseRequest with which this Database should be bound | ||
DatabaseRequest *corev1.ObjectReference `json:"databaseRequest"` | ||
|
||
// +optional | ||
Parameters map[string]string `json:"parameters,omitempty"` | ||
|
||
// ExistingDatabaseID is the unique id of the database. | ||
// This field will be empty when the Database is dynamically provisioned by operator. | ||
// +optional | ||
ExistingDatabaseID string `json:"existingBucketID,omitempty"` | ||
} | ||
|
||
type DatabaseStatus struct { | ||
// Ready is a boolean condition to reflect the successful creation | ||
// of a database. | ||
Ready bool `json:"ready,omitempty"` | ||
|
||
// DatabaseID is the unique id of the database | ||
// +optional | ||
DatabaseID string `json:"databaseID,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:scope=Cluster | ||
// +kubebuilder:subresource:status | ||
type Database struct { | ||
metav1.TypeMeta `json:",inline"` | ||
// +optional | ||
|
||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec DatabaseSpec `json:"spec,omitempty"` | ||
|
||
// +optional | ||
Status DatabaseStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
type DatabaseList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Database `json:"items"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
func init() { | ||
SchemeBuilder.Register(&DatabaseAccess{}, &DatabaseAccessList{}) | ||
} | ||
|
||
type DatabaseAccessSpec struct { | ||
// DatabaseRequestName is the name of the DatabaseRequest. | ||
DatabaseRequestName string `json:"databaseRequestName"` | ||
|
||
// DatabaseAccessClassName is the name of the DatabaseAccessClass | ||
DatabaseAccessClassName string `json:"bucketAccessClassName"` | ||
|
||
// CredentialsSecretName is the name of the secret that operator should populate | ||
// with the credentials. If a secret by this name already exists, then it is | ||
// assumed that credentials have already been generated. It is not overridden. | ||
// This secret is deleted when the DatabaseAccess is delted. | ||
CredentialsSecretName string `json:"credentialsSecretName"` | ||
} | ||
|
||
type DatabaseAccessStatus struct { | ||
// AccountID is the unique ID for the account in the OSP. It will be populated | ||
// by the COSI sidecar once access has been successfully granted. | ||
// +optional | ||
AccountID string `json:"accountID,omitempty"` | ||
|
||
// AccessGranted indicates the successful grant of privileges to access the bucket | ||
// +optional | ||
AccessGranted bool `json:"accessGranted"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:scope=Namespaced | ||
// +kubebuilder:subresource:status | ||
type DatabaseAccess struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec DatabaseAccessSpec `json:"spec,omitempty"` | ||
|
||
// +optional | ||
Status DatabaseAccessStatus `json:"status"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
type DatabaseAccessList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []DatabaseAccess `json:"items"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
func init() { | ||
SchemeBuilder.Register(&DatabaseClass{}, &DatabaseClassList{}) | ||
SchemeBuilder.Register(&DatabaseAccessClass{}, &DatabaseAccessClassList{}) | ||
} | ||
|
||
type AuthenticationType string | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:scope=Cluster | ||
type DatabaseClass struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// DriverName is the name of driver associated with this database | ||
DriverName string `json:"driverName"` | ||
|
||
// Parameters is an opaque map for passing in configuration to a driver | ||
// for creating the bucket | ||
// +optional | ||
Parameters map[string]string `json:"parameters,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
type DatabaseClassList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []DatabaseClass `json:"items"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:scope=Cluster | ||
type DatabaseAccessClass struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// DriverName is the name of driver associated with | ||
// this DatabaseAccess | ||
DriverName string `json:"driverName"` | ||
|
||
// AuthenticationType denotes the style of authentication | ||
AuthenticationType AuthenticationType `json:"authenticationType"` | ||
|
||
// Parameters is an opaque map for passing in configuration to a driver | ||
// for granting access to a bucket | ||
// +optional | ||
Parameters map[string]string `json:"parameters,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
type DatabaseAccessClassList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []DatabaseAccessClass `json:"items"` | ||
} |
Oops, something went wrong.