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)
|
||||
kubectl create namespace $(DEPLOYMENTNAMESPACE)
|
||||
endif
|
||||
kubectl apply -f manifests/crd.yaml
|
||||
kubectl apply -f $(MANIFESTPATHSTORAGE)
|
||||
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
|
||||
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
|
||||
|
@ -310,6 +311,7 @@ delete-operator:
|
|||
|
||||
.PHONY: redeploy-operator
|
||||
redeploy-operator: delete-operator manifests
|
||||
kubectl apply -f manifests/crd.yaml
|
||||
kubectl apply -f $(MANIFESTPATHSTORAGE)
|
||||
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
|
||||
kubectl get pods
|
||||
|
|
|
@ -11,6 +11,7 @@ State: In heavy development. DO NOT USE FOR ANY PRODUCTION LIKE PURPOSE! THINGS
|
|||
|
||||
```bash
|
||||
DOCKERNAMESPACE=<your dockerhub account> make
|
||||
kubectl apply -f manifests/crd.yaml
|
||||
kubectl apply -f manifests/arango-deployment-dev.yaml
|
||||
# To use `ArangoLocalStorage`, also run
|
||||
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:
|
||||
|
||||
```bash
|
||||
kubectl apply -f manifests/crd.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:
|
||||
- customresourcedefinitions
|
||||
verbs:
|
||||
- "*"
|
||||
- get
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: {{ .Deployment.ClusterRoleName }}
|
||||
name: {{ .Storage.ClusterRoleName }}
|
||||
rules:
|
||||
- apiGroups:
|
||||
- storage.arangodb.com
|
||||
|
@ -16,7 +16,7 @@ rules:
|
|||
resources:
|
||||
- customresourcedefinitions
|
||||
verbs:
|
||||
- "*"
|
||||
- get
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
|
@ -43,14 +43,14 @@ rules:
|
|||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: {{ .Deployment.ClusterRoleBindingName }}
|
||||
name: {{ .Storage.ClusterRoleBindingName }}
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: {{ .Deployment.ClusterRoleName }}
|
||||
name: {{ .Storage.ClusterRoleName }}
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: default
|
||||
namespace: {{ .Deployment.Namespace }}
|
||||
namespace: {{ .Storage.Namespace }}
|
||||
|
||||
{{- end -}}
|
|
@ -23,35 +23,17 @@
|
|||
package operator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
deplapi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
|
||||
lsapi "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/crd"
|
||||
)
|
||||
|
||||
// initResourceIfNeeded initializes the custom resource definition when
|
||||
// instructed to do so by the config.
|
||||
func (o *Operator) initResourceIfNeeded(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 {
|
||||
// waitForCRD waits for the CustomResourceDefinition (created externally)
|
||||
// to be ready.
|
||||
func (o *Operator) waitForCRD(enableDeployment, enableStorage bool) error {
|
||||
log := o.Dependencies.Log
|
||||
|
||||
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")
|
||||
if err := crd.WaitCRDReady(o.KubeExtCli, deplapi.ArangoDeploymentCRDName); err != nil {
|
||||
return maskAny(err)
|
||||
|
@ -59,10 +41,6 @@ func (o *Operator) initCRD(enableDeployment, enableStorage bool) error {
|
|||
}
|
||||
|
||||
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")
|
||||
if err := crd.WaitCRDReady(o.KubeExtCli, lsapi.ArangoLocalStorageCRDName); err != nil {
|
||||
return maskAny(err)
|
||||
|
|
|
@ -102,7 +102,7 @@ func (o *Operator) Run() {
|
|||
// onStartDeployment starts the deployment operator and run till given channel is closed.
|
||||
func (o *Operator) onStartDeployment(stop <-chan struct{}) {
|
||||
for {
|
||||
if err := o.initResourceIfNeeded(true, false); err == nil {
|
||||
if err := o.waitForCRD(true, false); err == nil {
|
||||
break
|
||||
} else {
|
||||
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.
|
||||
func (o *Operator) onStartStorage(stop <-chan struct{}) {
|
||||
for {
|
||||
if err := o.initResourceIfNeeded(false, true); err == nil {
|
||||
if err := o.waitForCRD(false, true); err == nil {
|
||||
break
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Resource initialization failed")
|
||||
|
|
|
@ -26,42 +26,13 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
||||
"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.
|
||||
func WaitCRDReady(clientset apiextensionsclient.Interface, crdName string) error {
|
||||
op := func() error {
|
||||
|
|
Loading…
Reference in a new issue