mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
Moved CRD creation to external yaml file
This commit is contained in:
parent
b5f529ffe5
commit
8382f7da78
9 changed files with 49 additions and 62 deletions
2
Makefile
2
Makefile
|
@ -242,6 +242,7 @@ ifneq ($(DEPLOYMENTNAMESPACE), default)
|
||||||
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
|
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
|
||||||
kubectl create namespace $(DEPLOYMENTNAMESPACE)
|
kubectl create namespace $(DEPLOYMENTNAMESPACE)
|
||||||
endif
|
endif
|
||||||
|
kubectl apply -f manifests/crd.yaml
|
||||||
kubectl apply -f $(MANIFESTPATHSTORAGE)
|
kubectl apply -f $(MANIFESTPATHSTORAGE)
|
||||||
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
|
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
|
||||||
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
|
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
|
||||||
|
@ -310,6 +311,7 @@ delete-operator:
|
||||||
|
|
||||||
.PHONY: redeploy-operator
|
.PHONY: redeploy-operator
|
||||||
redeploy-operator: delete-operator manifests
|
redeploy-operator: delete-operator manifests
|
||||||
|
kubectl apply -f manifests/crd.yaml
|
||||||
kubectl apply -f $(MANIFESTPATHSTORAGE)
|
kubectl apply -f $(MANIFESTPATHSTORAGE)
|
||||||
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
|
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
|
||||||
kubectl get pods
|
kubectl get pods
|
||||||
|
|
|
@ -11,6 +11,7 @@ State: In heavy development. DO NOT USE FOR ANY PRODUCTION LIKE PURPOSE! THINGS
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
DOCKERNAMESPACE=<your dockerhub account> make
|
DOCKERNAMESPACE=<your dockerhub account> make
|
||||||
|
kubectl apply -f manifests/crd.yaml
|
||||||
kubectl apply -f manifests/arango-deployment-dev.yaml
|
kubectl apply -f manifests/arango-deployment-dev.yaml
|
||||||
# To use `ArangoLocalStorage`, also run
|
# To use `ArangoLocalStorage`, also run
|
||||||
kubectl apply -f manifests/arango-storage-dev.yaml
|
kubectl apply -f manifests/arango-storage-dev.yaml
|
||||||
|
|
|
@ -6,6 +6,7 @@ The ArangoDB operator needs to be installed in your Kubernetes
|
||||||
cluster first. To do so, clone this repository and run:
|
cluster first. To do so, clone this repository and run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
kubectl apply -f manifests/crd.yaml
|
||||||
kubectl apply -f manifests/arango-deployment.yaml
|
kubectl apply -f manifests/arango-deployment.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
34
manifests/crd.yaml
Normal file
34
manifests/crd.yaml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
name: arangodeployments.database.arangodb.com
|
||||||
|
spec:
|
||||||
|
group: database.arangodb.com
|
||||||
|
names:
|
||||||
|
kind: ArangoDeployment
|
||||||
|
listKind: ArangoDeploymentList
|
||||||
|
plural: arangodeployments
|
||||||
|
shortNames:
|
||||||
|
- arangodb
|
||||||
|
- arango
|
||||||
|
singular: arangodeployment
|
||||||
|
scope: Namespaced
|
||||||
|
version: v1alpha
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
name: arangolocalstorages.storage.arangodb.com
|
||||||
|
spec:
|
||||||
|
group: storage.arangodb.com
|
||||||
|
names:
|
||||||
|
kind: ArangoLocalStorage
|
||||||
|
listKind: ArangoLocalStorageList
|
||||||
|
plural: arangolocalstorages
|
||||||
|
shortNames:
|
||||||
|
- arangostorage
|
||||||
|
singular: arangolocalstorage
|
||||||
|
scope: Namespaced
|
||||||
|
version: v1alpha
|
|
@ -15,7 +15,7 @@ rules:
|
||||||
resources:
|
resources:
|
||||||
- customresourcedefinitions
|
- customresourcedefinitions
|
||||||
verbs:
|
verbs:
|
||||||
- "*"
|
- get
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
resources:
|
resources:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ .Deployment.ClusterRoleName }}
|
name: {{ .Storage.ClusterRoleName }}
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- storage.arangodb.com
|
- storage.arangodb.com
|
||||||
|
@ -16,7 +16,7 @@ rules:
|
||||||
resources:
|
resources:
|
||||||
- customresourcedefinitions
|
- customresourcedefinitions
|
||||||
verbs:
|
verbs:
|
||||||
- "*"
|
- get
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
resources:
|
resources:
|
||||||
|
@ -43,14 +43,14 @@ rules:
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ .Deployment.ClusterRoleBindingName }}
|
name: {{ .Storage.ClusterRoleBindingName }}
|
||||||
roleRef:
|
roleRef:
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
name: {{ .Deployment.ClusterRoleName }}
|
name: {{ .Storage.ClusterRoleName }}
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: default
|
name: default
|
||||||
namespace: {{ .Deployment.Namespace }}
|
namespace: {{ .Storage.Namespace }}
|
||||||
|
|
||||||
{{- end -}}
|
{{- end -}}
|
|
@ -23,35 +23,17 @@
|
||||||
package operator
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
deplapi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
|
deplapi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
|
||||||
lsapi "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha"
|
lsapi "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha"
|
||||||
"github.com/arangodb/kube-arangodb/pkg/util/crd"
|
"github.com/arangodb/kube-arangodb/pkg/util/crd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// initResourceIfNeeded initializes the custom resource definition when
|
// waitForCRD waits for the CustomResourceDefinition (created externally)
|
||||||
// instructed to do so by the config.
|
// to be ready.
|
||||||
func (o *Operator) initResourceIfNeeded(enableDeployment, enableStorage bool) error {
|
func (o *Operator) waitForCRD(enableDeployment, enableStorage bool) error {
|
||||||
if o.Config.CreateCRD {
|
|
||||||
if err := o.initCRD(enableDeployment, enableStorage); err != nil {
|
|
||||||
return maskAny(fmt.Errorf("Failed to initialize Custom Resource Definition: %v", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// initCRD creates the CustomResourceDefinition and waits for it to be ready.
|
|
||||||
func (o *Operator) initCRD(enableDeployment, enableStorage bool) error {
|
|
||||||
log := o.Dependencies.Log
|
log := o.Dependencies.Log
|
||||||
|
|
||||||
if enableDeployment {
|
if enableDeployment {
|
||||||
log.Debug().Msg("Creating ArangoDeployment CRD")
|
|
||||||
if err := crd.CreateCRD(o.KubeExtCli, deplapi.SchemeGroupVersion, deplapi.ArangoDeploymentCRDName, deplapi.ArangoDeploymentResourceKind, deplapi.ArangoDeploymentResourcePlural, deplapi.ArangoDeploymentShortNames...); err != nil {
|
|
||||||
return maskAny(errors.Wrapf(err, "failed to create CRD: %v", err))
|
|
||||||
}
|
|
||||||
log.Debug().Msg("Waiting for ArangoDeployment CRD to be ready")
|
log.Debug().Msg("Waiting for ArangoDeployment CRD to be ready")
|
||||||
if err := crd.WaitCRDReady(o.KubeExtCli, deplapi.ArangoDeploymentCRDName); err != nil {
|
if err := crd.WaitCRDReady(o.KubeExtCli, deplapi.ArangoDeploymentCRDName); err != nil {
|
||||||
return maskAny(err)
|
return maskAny(err)
|
||||||
|
@ -59,10 +41,6 @@ func (o *Operator) initCRD(enableDeployment, enableStorage bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if enableStorage {
|
if enableStorage {
|
||||||
log.Debug().Msg("Creating ArangoLocalStorage CRD")
|
|
||||||
if err := crd.CreateCRD(o.KubeExtCli, lsapi.SchemeGroupVersion, lsapi.ArangoLocalStorageCRDName, lsapi.ArangoLocalStorageResourceKind, lsapi.ArangoLocalStorageResourcePlural, lsapi.ArangoLocalStorageShortNames...); err != nil {
|
|
||||||
return maskAny(errors.Wrapf(err, "failed to create CRD: %v", err))
|
|
||||||
}
|
|
||||||
log.Debug().Msg("Waiting for ArangoLocalStorage CRD to be ready")
|
log.Debug().Msg("Waiting for ArangoLocalStorage CRD to be ready")
|
||||||
if err := crd.WaitCRDReady(o.KubeExtCli, lsapi.ArangoLocalStorageCRDName); err != nil {
|
if err := crd.WaitCRDReady(o.KubeExtCli, lsapi.ArangoLocalStorageCRDName); err != nil {
|
||||||
return maskAny(err)
|
return maskAny(err)
|
||||||
|
|
|
@ -102,7 +102,7 @@ func (o *Operator) Run() {
|
||||||
// onStartDeployment starts the deployment operator and run till given channel is closed.
|
// onStartDeployment starts the deployment operator and run till given channel is closed.
|
||||||
func (o *Operator) onStartDeployment(stop <-chan struct{}) {
|
func (o *Operator) onStartDeployment(stop <-chan struct{}) {
|
||||||
for {
|
for {
|
||||||
if err := o.initResourceIfNeeded(true, false); err == nil {
|
if err := o.waitForCRD(true, false); err == nil {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
log.Error().Err(err).Msg("Resource initialization failed")
|
log.Error().Err(err).Msg("Resource initialization failed")
|
||||||
|
@ -116,7 +116,7 @@ func (o *Operator) onStartDeployment(stop <-chan struct{}) {
|
||||||
// onStartStorage starts the storage operator and run till given channel is closed.
|
// onStartStorage starts the storage operator and run till given channel is closed.
|
||||||
func (o *Operator) onStartStorage(stop <-chan struct{}) {
|
func (o *Operator) onStartStorage(stop <-chan struct{}) {
|
||||||
for {
|
for {
|
||||||
if err := o.initResourceIfNeeded(false, true); err == nil {
|
if err := o.waitForCRD(false, true); err == nil {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
log.Error().Err(err).Msg("Resource initialization failed")
|
log.Error().Err(err).Msg("Resource initialization failed")
|
||||||
|
|
|
@ -26,42 +26,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
|
|
||||||
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||||
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
|
||||||
"github.com/arangodb/kube-arangodb/pkg/util/retry"
|
"github.com/arangodb/kube-arangodb/pkg/util/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateCRD creates a custom resouce definition.
|
|
||||||
func CreateCRD(clientset apiextensionsclient.Interface, groupVersion schema.GroupVersion, crdName, rkind, rplural string, shortName ...string) error {
|
|
||||||
crd := &apiextensionsv1beta1.CustomResourceDefinition{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: crdName,
|
|
||||||
},
|
|
||||||
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
|
|
||||||
Group: groupVersion.Group,
|
|
||||||
Version: groupVersion.Version,
|
|
||||||
Scope: apiextensionsv1beta1.NamespaceScoped,
|
|
||||||
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
|
|
||||||
Plural: rplural,
|
|
||||||
Kind: rkind,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if len(shortName) != 0 {
|
|
||||||
crd.Spec.Names.ShortNames = shortName
|
|
||||||
}
|
|
||||||
_, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
|
|
||||||
if err != nil && !k8sutil.IsAlreadyExists(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WaitCRDReady waits for a custom resource definition with given name to be ready.
|
// WaitCRDReady waits for a custom resource definition with given name to be ready.
|
||||||
func WaitCRDReady(clientset apiextensionsclient.Interface, crdName string) error {
|
func WaitCRDReady(clientset apiextensionsclient.Interface, crdName string) error {
|
||||||
op := func() error {
|
op := func() error {
|
||||||
|
|
Loading…
Reference in a new issue