1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

Renamed custom resource to ArangoDeployment in database.arangodb.com namespace

This commit is contained in:
Ewout Prangsma 2018-02-13 13:49:04 +01:00
parent 4cecf54c92
commit 67546f805f
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698
34 changed files with 857 additions and 735 deletions

View file

@ -152,3 +152,14 @@ release-minor: $(RELEASE)
release-major: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=major
## Kubernetes utilities
minikube-start:
minikube start --cpus=4 --memory=6144
delete-operator:
kubectl delete -f examples/deployment.yaml || true
redeploy-operator: delete-operator
kubectl create -f examples/deployment.yaml
kubectl get pods

View file

@ -1,6 +1,6 @@
# Custom Resource
The ArangoDB operator creates and maintains ArangoDB clusters
The ArangoDB operator creates and maintains ArangoDB deployments
in a Kubernetes cluster, given a cluster specification.
This cluster specification is a CustomResource following
a CustomResourceDefinition created by the operator.
@ -8,8 +8,8 @@ a CustomResourceDefinition created by the operator.
Example minimal cluster definition:
```yaml
apiVersion: "cluster.arangodb.com/v1alpha"
kind: "Cluster"
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-arangodb-cluster"
spec:
@ -19,8 +19,8 @@ spec:
Example more elaborate cluster definition:
```yaml
apiVersion: "cluster.arangodb.com/v1alpha"
kind: "Cluster"
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-arangodb-cluster"
spec:
@ -46,7 +46,7 @@ spec:
## Specification reference
Below you'll find all settings of the `Cluster` custom resource.
Below you'll find all settings of the `ArangoDeployment` custom resource.
Several settings are for various groups of servers. These are indicated
with `<group>` where `<group>` can be any of:
@ -59,23 +59,23 @@ with `<group>` where `<group>` can be any of:
### `spec.mode: string`
This setting specifies the type of cluster you want to create.
This setting specifies the type of deployment you want to create.
Possible values are:
- `cluster` (default) Full cluster. Defaults to 3 agents, 3 dbservers & 3 coordinators.
- `resilientsingle` Resilient single pair. Defaults to 3 agents and 2 single servers.
- `single` Single server only (note this does not provide high availability or reliability).
This setting cannot be changed after the cluster has been created.
This setting cannot be changed after the deployment has been created.
### `spec.environment: string`
This setting specifies the type of environment in which the cluster is created.
This setting specifies the type of environment in which the deployment is created.
Possible values are:
- `development` (default) This value optimizes the cluster for development
use. It is possible to run a cluster on a small number of nodes (e.g. minikube).
- `production` This value optimizes the cluster for production use.
- `development` (default) This value optimizes the deployment for development
use. It is possible to run a deployment on a small number of nodes (e.g. minikube).
- `production` This value optimizes the deployment for production use.
It puts required affinity constraints on all pods to avoid agents & dbservers
from running on the same machine.

View file

@ -1,5 +1,5 @@
apiVersion: "cluster.arangodb.com/v1alpha"
kind: "Cluster"
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-arangodb-cluster"
spec:

View file

@ -0,0 +1,6 @@
apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
name: "example-single-arangodb-server"
spec:
mode: single

28
main.go
View file

@ -43,14 +43,20 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
"github.com/arangodb/k8s-operator/pkg/client"
"github.com/arangodb/k8s-operator/pkg/controller"
"github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned"
"github.com/arangodb/k8s-operator/pkg/logging"
"github.com/arangodb/k8s-operator/pkg/util/constants"
"github.com/arangodb/k8s-operator/pkg/util/k8sutil"
"github.com/arangodb/k8s-operator/pkg/util/retry"
)
const (
defaultServerHost = "0.0.0.0"
defaultServerPort = 8528
defaultLogLevel = "debug"
)
var (
projectVersion = "dev"
projectBuild = "dev"
@ -74,9 +80,9 @@ var (
func init() {
f := cmdMain.Flags()
f.StringVar(&server.host, "server.host", "0.0.0.0", "Host to listen on")
f.IntVar(&server.port, "server.port", 8528, "Port to listen on")
f.StringVar(&logLevel, "log.level", "info", "Set initial log level")
f.StringVar(&server.host, "server.host", defaultServerHost, "Host to listen on")
f.IntVar(&server.port, "server.port", defaultServerPort, "Port to listen on")
f.StringVar(&logLevel, "log.level", defaultLogLevel, "Set initial log level")
f.BoolVar(&createCRD, "operator.create-crd", true, "Disable to avoid create the custom resource definition")
}
@ -184,11 +190,7 @@ func newControllerConfigAndDeps(namespace, name string) (controller.Config, cont
if err != nil {
return controller.Config{}, controller.Dependencies{}, maskAny(fmt.Errorf("Failed to create k8b api extensions client: %s", err))
}
inClCfg, err := k8sutil.InClusterConfig()
if err != nil {
return controller.Config{}, controller.Dependencies{}, maskAny(fmt.Errorf("Failed to collect in-cluster config: %s", err))
}
clusterCRCli, err := versioned.NewForConfig(inClCfg)
databaseCRCli, err := client.NewInCluster()
if err != nil {
return controller.Config{}, controller.Dependencies{}, maskAny(fmt.Errorf("Failed to created versioned client: %s", err))
}
@ -199,10 +201,10 @@ func newControllerConfigAndDeps(namespace, name string) (controller.Config, cont
CreateCRD: createCRD,
}
deps := controller.Dependencies{
Log: logService.MustGetLogger("controller"),
KubeCli: kubecli,
KubeExtCli: kubeExtCli,
ClusterCRCli: clusterCRCli,
Log: logService.MustGetLogger("controller"),
KubeCli: kubecli,
KubeExtCli: kubeExtCli,
DatabaseCRCli: databaseCRCli,
}
return cfg, deps, nil

View file

@ -28,57 +28,59 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ArangoClusterList is a list of ArangoDB clusters.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ArangoClusterList struct {
// ArangoDeploymentList is a list of ArangoDB clusters.
type ArangoDeploymentList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ListMeta `json:"metadata,omitempty"`
Items []ArangoCluster `json:"items"`
Items []ArangoDeployment `json:"items"`
}
// ArangoCluster contains the entire Kubernetes info for an ArangoDB cluster
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ArangoCluster struct {
// ArangoDeployment contains the entire Kubernetes info for an ArangoDB database deployment.
type ArangoDeployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec"`
Status ClusterStatus `json:"status"`
Spec DeploymentSpec `json:"spec"`
Status DeploymentStatus `json:"status"`
}
func (c *ArangoCluster) AsOwner() metav1.OwnerReference {
func (c *ArangoDeployment) AsOwner() metav1.OwnerReference {
controller := true
return metav1.OwnerReference{
APIVersion: SchemeGroupVersion.String(),
Kind: ArangoClusterResourceKind,
Kind: ArangoDeploymentResourceKind,
Name: c.Name,
UID: c.UID,
Controller: &controller,
}
}
// ClusterMode specifies the type of cluster to create.
type ClusterMode string
// DeploymentMode specifies the type of ArangoDB deployment to create.
type DeploymentMode string
const (
// ClusterModeSingle yields a single server
ClusterModeSingle ClusterMode = "single"
// ClusterModeResilientSingle yields an agency and a resilient-single server pair
ClusterModeResilientSingle ClusterMode = "resilientsingle"
// ClusterModeCluster yields an full cluster (agency, dbservers & coordinators)
ClusterModeCluster ClusterMode = "cluster"
// DeploymentModeSingle yields a single server
DeploymentModeSingle DeploymentMode = "single"
// DeploymentModeResilientSingle yields an agency and a resilient-single server pair
DeploymentModeResilientSingle DeploymentMode = "resilientsingle"
// DeploymentModeCluster yields an full cluster (agency, dbservers & coordinators)
DeploymentModeCluster DeploymentMode = "cluster"
)
// Validate the mode.
// Return errors when validation fails, nil on success.
func (m ClusterMode) Validate() error {
func (m DeploymentMode) Validate() error {
switch m {
case ClusterModeSingle, ClusterModeResilientSingle, ClusterModeCluster:
case DeploymentModeSingle, DeploymentModeResilientSingle, DeploymentModeCluster:
return nil
default:
return maskAny(errors.Wrapf(ValidationError, "Unknown cluster mode: '%s'", string(m)))
return maskAny(errors.Wrapf(ValidationError, "Unknown deployment mode: '%s'", string(m)))
}
}
@ -135,12 +137,12 @@ func validatePullPolicy(v v1.PullPolicy) error {
}
}
// ClusterSpec contains the spec part of a Cluster resource.
type ClusterSpec struct {
Mode ClusterMode `json:"mode,omitempty"`
Environment Environment `json:"environment,omitempty"`
StorageEngine StorageEngine `json:"storageEngine,omitempty"`
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
// DeploymentSpec contains the spec part of a ArangoDeployment resource.
type DeploymentSpec struct {
Mode DeploymentMode `json:"mode,omitempty"`
Environment Environment `json:"environment,omitempty"`
StorageEngine StorageEngine `json:"storageEngine,omitempty"`
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
RocksDB struct {
Encryption struct {
@ -160,9 +162,9 @@ type ClusterSpec struct {
}
// SetDefaults fills in default values when a field is not specified.
func (cs *ClusterSpec) SetDefaults() {
func (cs *DeploymentSpec) SetDefaults() {
if cs.Mode == "" {
cs.Mode = ClusterModeCluster
cs.Mode = DeploymentModeCluster
}
if cs.Environment == "" {
cs.Environment = EnvironmentDevelopment
@ -174,7 +176,7 @@ func (cs *ClusterSpec) SetDefaults() {
// Validate the specification.
// Return errors when validation fails, nil on success.
func (cs *ClusterSpec) Validate() error {
func (cs *DeploymentSpec) Validate() error {
if err := cs.Mode.Validate(); err != nil {
return maskAny(err)
}

View file

@ -22,31 +22,31 @@
package v1alpha
type ClusterState string
type DeploymentState string
const (
ClusterStateNone ClusterState = ""
ClusterStateCreating ClusterState = "Creating"
ClusterStateRunning ClusterState = "Running"
ClusterStateScaling ClusterState = "Scaling"
ClusterStateUpgrading ClusterState = "Upgrading"
ClusterStateFailed ClusterState = "Failed"
DeploymentStateNone DeploymentState = ""
DeploymentStateCreating DeploymentState = "Creating"
DeploymentStateRunning DeploymentState = "Running"
DeploymentStateScaling DeploymentState = "Scaling"
DeploymentStateUpgrading DeploymentState = "Upgrading"
DeploymentStateFailed DeploymentState = "Failed"
)
// IsFailed returns true if given state is ClusterStateFailed
func (cs ClusterState) IsFailed() bool {
return cs == ClusterStateFailed
// IsFailed returns true if given state is DeploymentStateFailed
func (cs DeploymentState) IsFailed() bool {
return cs == DeploymentStateFailed
}
// ClusterStatus contains the status part of a Cluster resource.
type ClusterStatus struct {
State ClusterState `json:"state"`
Reason string `json:"reason,omitempty"` // Reason for current state
// DeploymentStatus contains the status part of a Cluster resource.
type DeploymentStatus struct {
State DeploymentState `json:"state"`
Reason string `json:"reason,omitempty"` // Reason for current state
Members ClusterStatusMembers `json:"members"`
Members DeploymentStatusMembers `json:"members"`
}
type ClusterStatusMembers struct {
type DeploymentStatusMembers struct {
Single []MemberStatus `json:"single,omitempty"`
Agents []MemberStatus `json:"agents,omitempty"`
DBServers []MemberStatus `json:"dbservers,omitempty"`

View file

@ -21,5 +21,5 @@
//
// +k8s:deepcopy-gen=package
// +groupName=cluster.arangodb.com
// +groupName=database.arangodb.com
package v1alpha

View file

@ -29,20 +29,20 @@ import (
)
const (
ArangoClusterResourceKind = "Cluster"
ArangoClusterResourcePlural = "clusters"
groupName = "cluster.arangodb.com"
ArangoDeploymentResourceKind = "ArangoDeployment"
ArangoDeploymentResourcePlural = "deployments"
groupName = "database.arangodb.com"
)
var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
SchemeGroupVersion = schema.GroupVersion{Group: groupName, Version: "v1alpha"}
ArangoClusterCRDName = ArangoClusterResourcePlural + "." + groupName
SchemeGroupVersion = schema.GroupVersion{Group: groupName, Version: "v1alpha"}
ArangoDeploymentCRDName = ArangoDeploymentResourcePlural + "." + groupName
)
// Resource gets an EtcdCluster GroupResource for a specified resource
// Resource gets an ArangoCluster GroupResource for a specified resource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
@ -50,8 +50,8 @@ func Resource(resource string) schema.GroupResource {
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
func addKnownTypes(s *runtime.Scheme) error {
s.AddKnownTypes(SchemeGroupVersion,
&ArangoCluster{},
&ArangoClusterList{},
&ArangoDeployment{},
&ArangoDeploymentList{},
)
metav1.AddToGroupVersion(s, SchemeGroupVersion)
return nil

View file

@ -29,7 +29,7 @@ import (
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ArangoCluster) DeepCopyInto(out *ArangoCluster) {
func (in *ArangoDeployment) DeepCopyInto(out *ArangoDeployment) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
@ -38,18 +38,18 @@ func (in *ArangoCluster) DeepCopyInto(out *ArangoCluster) {
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArangoCluster.
func (in *ArangoCluster) DeepCopy() *ArangoCluster {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArangoDeployment.
func (in *ArangoDeployment) DeepCopy() *ArangoDeployment {
if in == nil {
return nil
}
out := new(ArangoCluster)
out := new(ArangoDeployment)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ArangoCluster) DeepCopyObject() runtime.Object {
func (in *ArangoDeployment) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
@ -57,13 +57,13 @@ func (in *ArangoCluster) DeepCopyObject() runtime.Object {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ArangoClusterList) DeepCopyInto(out *ArangoClusterList) {
func (in *ArangoDeploymentList) DeepCopyInto(out *ArangoDeploymentList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]ArangoCluster, len(*in))
*out = make([]ArangoDeployment, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
@ -71,18 +71,18 @@ func (in *ArangoClusterList) DeepCopyInto(out *ArangoClusterList) {
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArangoClusterList.
func (in *ArangoClusterList) DeepCopy() *ArangoClusterList {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArangoDeploymentList.
func (in *ArangoDeploymentList) DeepCopy() *ArangoDeploymentList {
if in == nil {
return nil
}
out := new(ArangoClusterList)
out := new(ArangoDeploymentList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ArangoClusterList) DeepCopyObject() runtime.Object {
func (in *ArangoDeploymentList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
@ -90,7 +90,7 @@ func (in *ArangoClusterList) DeepCopyObject() runtime.Object {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
*out = *in
out.RocksDB = in.RocksDB
out.Authentication = in.Authentication
@ -98,35 +98,35 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSpec.
func (in *ClusterSpec) DeepCopy() *ClusterSpec {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentSpec.
func (in *DeploymentSpec) DeepCopy() *DeploymentSpec {
if in == nil {
return nil
}
out := new(ClusterSpec)
out := new(DeploymentSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) {
func (in *DeploymentStatus) DeepCopyInto(out *DeploymentStatus) {
*out = *in
in.Members.DeepCopyInto(&out.Members)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatus.
func (in *ClusterStatus) DeepCopy() *ClusterStatus {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentStatus.
func (in *DeploymentStatus) DeepCopy() *DeploymentStatus {
if in == nil {
return nil
}
out := new(ClusterStatus)
out := new(DeploymentStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterStatusMembers) DeepCopyInto(out *ClusterStatusMembers) {
func (in *DeploymentStatusMembers) DeepCopyInto(out *DeploymentStatusMembers) {
*out = *in
if in.Single != nil {
in, out := &in.Single, &out.Single
@ -161,12 +161,12 @@ func (in *ClusterStatusMembers) DeepCopyInto(out *ClusterStatusMembers) {
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatusMembers.
func (in *ClusterStatusMembers) DeepCopy() *ClusterStatusMembers {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentStatusMembers.
func (in *DeploymentStatusMembers) DeepCopy() *DeploymentStatusMembers {
if in == nil {
return nil
}
out := new(ClusterStatusMembers)
out := new(DeploymentStatusMembers)
in.DeepCopyInto(out)
return out
}

79
pkg/client/client.go Normal file
View file

@ -0,0 +1,79 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Ewout Prangsma
//
package client
import (
"github.com/pkg/errors"
"k8s.io/client-go/rest"
"github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned"
"github.com/arangodb/k8s-operator/pkg/util/k8sutil"
)
var (
maskAny = errors.WithStack
)
// MustNewInCluster creates an in-cluster client, or panics
// when a failure is detected.
func MustNewInCluster() versioned.Interface {
cli, err := NewInCluster()
if err != nil {
panic(err)
}
return cli
}
// MustNew creates a client with given config, or panics
// when a failure is detected.
func MustNew(cfg *rest.Config) versioned.Interface {
cli, err := New(cfg)
if err != nil {
panic(err)
}
return cli
}
// NewInCluster creates an in-cluster client, or returns an error
// when a failure is detected.
func NewInCluster() (versioned.Interface, error) {
cfg, err := k8sutil.InClusterConfig()
if err != nil {
return nil, maskAny(err)
}
cli, err := New(cfg)
if err != nil {
return nil, maskAny(err)
}
return cli, nil
}
// New creates a client with given config, or returns an error
// when a failure is detected.
func New(cfg *rest.Config) (versioned.Interface, error) {
cli, err := versioned.NewForConfig(cfg)
if err != nil {
return nil, maskAny(err)
}
return cli, nil
}

View file

@ -36,7 +36,7 @@ import (
"k8s.io/client-go/tools/cache"
api "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
"github.com/arangodb/k8s-operator/pkg/cluster"
"github.com/arangodb/k8s-operator/pkg/deployment"
"github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned"
"github.com/arangodb/k8s-operator/pkg/metrics"
)
@ -46,23 +46,23 @@ const (
)
var (
clustersCreated = metrics.MustRegisterCounter("controller", "clusters_created", "Number of clusters that have been created")
clustersDeleted = metrics.MustRegisterCounter("controller", "clusters_deleted", "Number of clusters that have been deleted")
clustersFailed = metrics.MustRegisterCounter("controller", "clusters_failed", "Number of clusters that have failed")
clustersModified = metrics.MustRegisterCounter("controller", "clusters_modified", "Number of cluster modifications")
clustersCurrent = metrics.MustRegisterGauge("controller", "clusters", "Number of clusters currently being managed")
deploymentsCreated = metrics.MustRegisterCounter("controller", "deployments_created", "Number of deployments that have been created")
deploymentsDeleted = metrics.MustRegisterCounter("controller", "deployments_deleted", "Number of deployments that have been deleted")
deploymentsFailed = metrics.MustRegisterCounter("controller", "deployments_failed", "Number of deployments that have failed")
deploymentsModified = metrics.MustRegisterCounter("controller", "deployments_modified", "Number of deployment modifications")
deploymentsCurrent = metrics.MustRegisterGauge("controller", "deployments", "Number of deployments currently being managed")
)
type Event struct {
Type kwatch.EventType
Object *api.ArangoCluster
Object *api.ArangoDeployment
}
type Controller struct {
Config
Dependencies
clusters map[string]*cluster.Cluster
deployments map[string]*deployment.Deployment
}
type Config struct {
@ -72,10 +72,10 @@ type Config struct {
}
type Dependencies struct {
Log zerolog.Logger
KubeCli kubernetes.Interface
KubeExtCli apiextensionsclient.Interface
ClusterCRCli versioned.Interface
Log zerolog.Logger
KubeCli kubernetes.Interface
KubeExtCli apiextensionsclient.Interface
DatabaseCRCli versioned.Interface
}
// NewController instantiates a new controller from given config & dependencies.
@ -83,7 +83,7 @@ func NewController(config Config, deps Dependencies) (*Controller, error) {
c := &Controller{
Config: config,
Dependencies: deps,
clusters: make(map[string]*cluster.Cluster),
deployments: make(map[string]*deployment.Deployment),
}
return c, nil
}
@ -110,16 +110,19 @@ func (c *Controller) Start() error {
// run the controller.
// This registers a listener and waits until the process stops.
func (c *Controller) run() {
log := c.Dependencies.Log
log.Info().Msgf("Running controller in namespace '%s'", c.Config.Namespace)
source := cache.NewListWatchFromClient(
c.Dependencies.ClusterCRCli.ClusterV1alpha().RESTClient(),
api.ArangoClusterResourcePlural,
c.Dependencies.DatabaseCRCli.DatabaseV1alpha().RESTClient(),
api.ArangoDeploymentResourcePlural,
c.Config.Namespace,
fields.Everything())
_, informer := cache.NewIndexerInformer(source, &api.ArangoCluster{}, 0, cache.ResourceEventHandlerFuncs{
AddFunc: c.onAddArangoCluster,
UpdateFunc: c.onUpdateArangoCluster,
DeleteFunc: c.onDeleteArangoCluster,
_, informer := cache.NewIndexerInformer(source, &api.ArangoDeployment{}, 0, cache.ResourceEventHandlerFuncs{
AddFunc: c.onAddArangoDeployment,
UpdateFunc: c.onUpdateArangoDeployment,
DeleteFunc: c.onDeleteArangoDeployment,
}, cache.Indexers{})
ctx := context.TODO()
@ -127,127 +130,139 @@ func (c *Controller) run() {
informer.Run(ctx.Done())
}
// onAddArangoCluster cluster addition callback
func (c *Controller) onAddArangoCluster(obj interface{}) {
c.syncArangoCluster(obj.(*api.ArangoCluster))
// onAddArangoDeployment deployment addition callback
func (c *Controller) onAddArangoDeployment(obj interface{}) {
log := c.Dependencies.Log
apiObject := obj.(*api.ArangoDeployment)
log.Debug().
Str("name", apiObject.GetObjectMeta().GetName()).
Msg("ArangoDeployment added")
c.syncArangoDeployment(apiObject)
}
// onUpdateArangoCluster cluster update callback
func (c *Controller) onUpdateArangoCluster(oldObj, newObj interface{}) {
c.syncArangoCluster(newObj.(*api.ArangoCluster))
// onUpdateArangoDeployment deployment update callback
func (c *Controller) onUpdateArangoDeployment(oldObj, newObj interface{}) {
log := c.Dependencies.Log
apiObject := newObj.(*api.ArangoDeployment)
log.Debug().
Str("name", apiObject.GetObjectMeta().GetName()).
Msg("ArangoDeployment updated")
c.syncArangoDeployment(apiObject)
}
// onDeleteArangoCluster cluster delete callback
func (c *Controller) onDeleteArangoCluster(obj interface{}) {
clus, ok := obj.(*api.ArangoCluster)
// onDeleteArangoDeployment deployment delete callback
func (c *Controller) onDeleteArangoDeployment(obj interface{}) {
apiObject, ok := obj.(*api.ArangoDeployment)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
panic(fmt.Sprintf("unknown object from EtcdCluster delete event: %#v", obj))
panic(fmt.Sprintf("unknown object from ArangoDeployment delete event: %#v", obj))
}
clus, ok = tombstone.Obj.(*api.ArangoCluster)
apiObject, ok = tombstone.Obj.(*api.ArangoDeployment)
if !ok {
panic(fmt.Sprintf("Tombstone contained object that is not an ArangoCluster: %#v", obj))
panic(fmt.Sprintf("Tombstone contained object that is not an ArangoDeployment: %#v", obj))
}
}
ev := &Event{
Type: kwatch.Deleted,
Object: clus,
Object: apiObject,
}
// pt.start()
err := c.handleClusterEvent(ev)
err := c.handleDeploymentEvent(ev)
if err != nil {
c.Dependencies.Log.Warn().Err(err).Msg("Failed to handle event")
}
//pt.stop()
}
// syncArangoCluster synchronized the given cluster.
func (c *Controller) syncArangoCluster(apiCluster *api.ArangoCluster) {
// syncArangoDeployment synchronized the given deployment.
func (c *Controller) syncArangoDeployment(apiObject *api.ArangoDeployment) {
ev := &Event{
Type: kwatch.Added,
Object: apiCluster,
Object: apiObject,
}
// re-watch or restart could give ADD event.
// If for an ADD event the cluster spec is invalid then it is not added to the local cache
// so modifying that cluster will result in another ADD event
if _, ok := c.clusters[apiCluster.Name]; ok {
// so modifying that deployment will result in another ADD event
if _, ok := c.deployments[apiObject.Name]; ok {
ev.Type = kwatch.Modified
}
//pt.start()
err := c.handleClusterEvent(ev)
err := c.handleDeploymentEvent(ev)
if err != nil {
c.Dependencies.Log.Warn().Err(err).Msg("Failed to handle event")
}
//pt.stop()
}
// handleClusterEvent processed the given event.
func (c *Controller) handleClusterEvent(event *Event) error {
apiCluster := event.Object
// handleDeploymentEvent processed the given event.
func (c *Controller) handleDeploymentEvent(event *Event) error {
apiObject := event.Object
if apiCluster.Status.State.IsFailed() {
clustersFailed.Inc()
if apiObject.Status.State.IsFailed() {
deploymentsFailed.Inc()
if event.Type == kwatch.Deleted {
delete(c.clusters, apiCluster.Name)
delete(c.deployments, apiObject.Name)
return nil
}
return maskAny(fmt.Errorf("ignore failed cluster (%s). Please delete its CR", apiCluster.Name))
return maskAny(fmt.Errorf("ignore failed deployment (%s). Please delete its CR", apiObject.Name))
}
// Fill in defaults
apiCluster.Spec.SetDefaults()
// Validate cluster spec
if err := apiCluster.Spec.Validate(); err != nil {
return maskAny(errors.Wrapf(err, "invalid cluster spec. please fix the following problem with the cluster spec: %v", err))
apiObject.Spec.SetDefaults()
// Validate deployment spec
if err := apiObject.Spec.Validate(); err != nil {
return maskAny(errors.Wrapf(err, "invalid deployment spec. please fix the following problem with the deployment spec: %v", err))
}
switch event.Type {
case kwatch.Added:
if _, ok := c.clusters[apiCluster.Name]; ok {
return maskAny(fmt.Errorf("unsafe state. cluster (%s) was created before but we received event (%s)", apiCluster.Name, event.Type))
if _, ok := c.deployments[apiObject.Name]; ok {
return maskAny(fmt.Errorf("unsafe state. deployment (%s) was created before but we received event (%s)", apiObject.Name, event.Type))
}
cfg, deps := c.makeClusterConfigAndDeps()
nc, err := cluster.NewCluster(cfg, deps, apiCluster)
cfg, deps := c.makeDeploymentConfigAndDeps()
nc, err := deployment.New(cfg, deps, apiObject)
if err != nil {
return maskAny(fmt.Errorf("failed to create cluster: %s", err))
return maskAny(fmt.Errorf("failed to create deployment: %s", err))
}
c.clusters[apiCluster.Name] = nc
c.deployments[apiObject.Name] = nc
clustersCreated.Inc()
clustersCurrent.Set(float64(len(c.clusters)))
deploymentsCreated.Inc()
deploymentsCurrent.Set(float64(len(c.deployments)))
case kwatch.Modified:
if _, ok := c.clusters[apiCluster.Name]; !ok {
return maskAny(fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", apiCluster.Name, event.Type))
depl, ok := c.deployments[apiObject.Name]
if !ok {
return maskAny(fmt.Errorf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type))
}
c.clusters[apiCluster.Name].Update(apiCluster)
clustersModified.Inc()
depl.Update(apiObject)
deploymentsModified.Inc()
case kwatch.Deleted:
if _, ok := c.clusters[apiCluster.Name]; !ok {
return maskAny(fmt.Errorf("unsafe state. cluster (%s) was never created but we received event (%s)", apiCluster.Name, event.Type))
depl, ok := c.deployments[apiObject.Name]
if !ok {
return maskAny(fmt.Errorf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type))
}
c.clusters[apiCluster.Name].Delete()
delete(c.clusters, apiCluster.Name)
clustersDeleted.Inc()
clustersCurrent.Set(float64(len(c.clusters)))
depl.Delete()
delete(c.deployments, apiObject.Name)
deploymentsDeleted.Inc()
deploymentsCurrent.Set(float64(len(c.deployments)))
}
return nil
}
// makeClusterConfigAndDeps creates a Config & Dependencies object for a new cluster.
func (c *Controller) makeClusterConfigAndDeps() (cluster.Config, cluster.Dependencies) {
cfg := cluster.Config{
// makeDeploymentConfigAndDeps creates a Config & Dependencies object for a new cluster.
func (c *Controller) makeDeploymentConfigAndDeps() (deployment.Config, deployment.Dependencies) {
cfg := deployment.Config{
ServiceAccount: c.Config.ServiceAccount,
}
deps := cluster.Dependencies{
Log: c.Dependencies.Log,
KubeCli: c.Dependencies.KubeCli,
ClusterCRCli: c.Dependencies.ClusterCRCli,
deps := deployment.Dependencies{
Log: c.Dependencies.Log,
KubeCli: c.Dependencies.KubeCli,
DatabaseCRCli: c.Dependencies.DatabaseCRCli,
}
return cfg, deps
}

View file

@ -44,11 +44,16 @@ func (c *Controller) initResourceIfNeeded() error {
// initCRD creates the CustomResourceDefinition and waits for it to be ready.
func (c *Controller) initCRD() error {
if err := k8sutil.CreateCRD(c.KubeExtCli, api.ArangoClusterCRDName, api.ArangoClusterResourceKind, api.ArangoClusterResourcePlural, "arangodb"); err != nil {
log := c.Dependencies.Log
log.Info().Msg("Calling CreateCRD")
if err := k8sutil.CreateCRD(c.KubeExtCli, api.ArangoDeploymentCRDName, api.ArangoDeploymentResourceKind, api.ArangoDeploymentResourcePlural, "arangodb"); err != nil {
return maskAny(errors.Wrapf(err, "failed to create CRD: %v", err))
}
if err := k8sutil.WaitCRDReady(c.KubeExtCli, api.ArangoClusterCRDName); err != nil {
log.Info().Msg("Waiting for CRD ready")
if err := k8sutil.WaitCRDReady(c.KubeExtCli, api.ArangoDeploymentCRDName); err != nil {
return maskAny(err)
}
log.Info().Msg("CRD is ready")
return nil
}

View file

@ -20,7 +20,7 @@
// Author Ewout Prangsma
//
package cluster
package deployment
import (
"fmt"
@ -37,78 +37,80 @@ import (
"github.com/arangodb/k8s-operator/pkg/util/retry"
)
// Config holds configuration settings for a Deployment
type Config struct {
ServiceAccount string
}
// Dependencies holds dependent services for a Deployment
type Dependencies struct {
Log zerolog.Logger
KubeCli kubernetes.Interface
ClusterCRCli versioned.Interface
Log zerolog.Logger
KubeCli kubernetes.Interface
DatabaseCRCli versioned.Interface
}
// clusterEventType strongly typed type of event
type clusterEventType string
// deploymentEventType strongly typed type of event
type deploymentEventType string
const (
eventModifyCluster clusterEventType = "Modify"
eventModifyDeployment deploymentEventType = "Modify"
)
// clusterType holds an event passed from the controller to the cluster.
type clusterEvent struct {
Type clusterEventType
Cluster *api.ArangoCluster
// deploymentEvent holds an event passed from the controller to the deployment.
type deploymentEvent struct {
Type deploymentEventType
Deployment *api.ArangoDeployment
}
const (
clusterEventQueueSize = 100
deploymentEventQueueSize = 100
)
// Cluster is the in process state of an ArangoDB cluster.
type Cluster struct {
cluster *api.ArangoCluster // API object
status api.ClusterStatus // Internal status of the CR
config Config
deps Dependencies
// Deployment is the in process state of an ArangoDeployment.
type Deployment struct {
apiObject *api.ArangoDeployment // API object
status api.DeploymentStatus // Internal status of the CR
config Config
deps Dependencies
eventCh chan *clusterEvent
eventCh chan *deploymentEvent
stopCh chan struct{}
}
// NewCluster creates a new Cluster from the given API object.
func NewCluster(config Config, deps Dependencies, cluster *api.ArangoCluster) (*Cluster, error) {
if err := cluster.Spec.Validate(); err != nil {
// New creates a new Deployment from the given API object.
func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*Deployment, error) {
if err := apiObject.Spec.Validate(); err != nil {
return nil, maskAny(err)
}
c := &Cluster{
cluster: cluster,
status: *(cluster.Status.DeepCopy()),
config: config,
deps: deps,
eventCh: make(chan *clusterEvent, clusterEventQueueSize),
stopCh: make(chan struct{}),
c := &Deployment{
apiObject: apiObject,
status: *(apiObject.Status.DeepCopy()),
config: config,
deps: deps,
eventCh: make(chan *deploymentEvent, deploymentEventQueueSize),
stopCh: make(chan struct{}),
}
return c, nil
}
// Update the cluster.
// This sends an update event in the cluster event queue.
func (c *Cluster) Update(cluster *api.ArangoCluster) {
c.send(&clusterEvent{
Type: eventModifyCluster,
Cluster: cluster,
// Update the deployment.
// This sends an update event in the deployment event queue.
func (c *Deployment) Update(apiObject *api.ArangoDeployment) {
c.send(&deploymentEvent{
Type: eventModifyDeployment,
Deployment: apiObject,
})
}
// Delete the cluster.
// Called when the cluster was deleted by the user.
func (c *Cluster) Delete() {
c.deps.Log.Info().Msg("cluster is deleted by user")
// Delete the deployment.
// Called when the deployment was deleted by the user.
func (c *Deployment) Delete() {
c.deps.Log.Info().Msg("deployment is deleted by user")
close(c.stopCh)
}
// send given event into the cluster event queue.
func (c *Cluster) send(ev *clusterEvent) {
// send given event into the deployment event queue.
func (c *Deployment) send(ev *deploymentEvent) {
select {
case c.eventCh <- ev:
l, ecap := len(c.eventCh), cap(c.eventCh)
@ -125,10 +127,10 @@ func (c *Cluster) send(ev *clusterEvent) {
// run is the core the core worker.
// It processes the event queue and polls the state of generated
// resource on a regular basis.
func (c *Cluster) run() {
func (c *Deployment) run() {
log := c.deps.Log
c.status.State = api.ClusterStateRunning
c.status.State = api.DeploymentStateRunning
if err := c.updateCRStatus(); err != nil {
log.Warn().Err(err).Msg("update initial CR status failed")
}
@ -143,7 +145,7 @@ func (c *Cluster) run() {
case event := <-c.eventCh:
// Got event from event queue
switch event.Type {
case eventModifyCluster:
case eventModifyDeployment:
if err := c.handleUpdateEvent(event); err != nil {
log.Error().Err(err).Msg("handle update event failed")
c.status.Reason = err.Error()
@ -157,41 +159,41 @@ func (c *Cluster) run() {
}
}
// handleUpdateEvent processes the given event coming from the cluster event queue.
func (c *Cluster) handleUpdateEvent(event *clusterEvent) error {
// handleUpdateEvent processes the given event coming from the deployment event queue.
func (c *Deployment) handleUpdateEvent(event *deploymentEvent) error {
// TODO
return nil
}
// Update the status of the API object from the internal status
func (c *Cluster) updateCRStatus() error {
if reflect.DeepEqual(c.cluster.Status, c.status) {
func (c *Deployment) updateCRStatus() error {
if reflect.DeepEqual(c.apiObject.Status, c.status) {
// Nothing has changed
return nil
}
// Send update to API server
newCluster := c.cluster
newCluster.Status = c.status
newCluster, err := c.deps.ClusterCRCli.ClusterV1alpha().ArangoClusters(c.cluster.Namespace).Update(c.cluster)
update := *c.apiObject
update.Status = c.status
newAPIObject, err := c.deps.DatabaseCRCli.DatabaseV1alpha().ArangoDeployments(c.apiObject.Namespace).Update(&update)
if err != nil {
return maskAny(fmt.Errorf("failed to update CR status: %v", err))
}
// Update internal object
c.cluster = newCluster
c.apiObject = newAPIObject
return nil
}
// reportFailedStatus sets the status of the cluster to Failed and keeps trying to forward
// reportFailedStatus sets the status of the deployment to Failed and keeps trying to forward
// that to the API server.
func (c *Cluster) reportFailedStatus() {
func (c *Deployment) reportFailedStatus() {
log := c.deps.Log
log.Info().Msg("cluster failed. Reporting failed reason...")
log.Info().Msg("deployment failed. Reporting failed reason...")
op := func() error {
c.status.State = api.ClusterStateFailed
c.status.State = api.DeploymentStateFailed
err := c.updateCRStatus()
if err == nil || k8sutil.IsNotFound(err) {
// Status has been updated
@ -203,7 +205,7 @@ func (c *Cluster) reportFailedStatus() {
return maskAny(err)
}
cl, err := c.deps.ClusterCRCli.ClusterV1alpha().ArangoClusters(c.cluster.Namespace).Get(c.cluster.Name, metav1.GetOptions{})
depl, err := c.deps.DatabaseCRCli.DatabaseV1alpha().ArangoDeployments(c.apiObject.Namespace).Get(c.apiObject.Name, metav1.GetOptions{})
if err != nil {
// Update (PUT) will return conflict even if object is deleted since we have UID set in object.
// Because it will check UID first and return something like:
@ -214,7 +216,7 @@ func (c *Cluster) reportFailedStatus() {
log.Warn().Err(err).Msg("retry report status: fail to get latest version")
return maskAny(err)
}
c.cluster = cl
c.apiObject = depl
return maskAny(fmt.Errorf("retry needed"))
}

View file

@ -20,7 +20,7 @@
// Author Ewout Prangsma
//
package cluster
package deployment
import "github.com/pkg/errors"

View file

@ -20,7 +20,7 @@
package versioned
import (
clusterv1alpha "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/typed/arangodb/v1alpha"
databasev1alpha "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/typed/arangodb/v1alpha"
glog "github.com/golang/glog"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
@ -29,27 +29,27 @@ import (
type Interface interface {
Discovery() discovery.DiscoveryInterface
ClusterV1alpha() clusterv1alpha.ClusterV1alphaInterface
DatabaseV1alpha() databasev1alpha.DatabaseV1alphaInterface
// Deprecated: please explicitly pick a version if possible.
Cluster() clusterv1alpha.ClusterV1alphaInterface
Database() databasev1alpha.DatabaseV1alphaInterface
}
// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
*discovery.DiscoveryClient
clusterV1alpha *clusterv1alpha.ClusterV1alphaClient
databaseV1alpha *databasev1alpha.DatabaseV1alphaClient
}
// ClusterV1alpha retrieves the ClusterV1alphaClient
func (c *Clientset) ClusterV1alpha() clusterv1alpha.ClusterV1alphaInterface {
return c.clusterV1alpha
// DatabaseV1alpha retrieves the DatabaseV1alphaClient
func (c *Clientset) DatabaseV1alpha() databasev1alpha.DatabaseV1alphaInterface {
return c.databaseV1alpha
}
// Deprecated: Cluster retrieves the default version of ClusterClient.
// Deprecated: Database retrieves the default version of DatabaseClient.
// Please explicitly pick a version.
func (c *Clientset) Cluster() clusterv1alpha.ClusterV1alphaInterface {
return c.clusterV1alpha
func (c *Clientset) Database() databasev1alpha.DatabaseV1alphaInterface {
return c.databaseV1alpha
}
// Discovery retrieves the DiscoveryClient
@ -68,7 +68,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) {
}
var cs Clientset
var err error
cs.clusterV1alpha, err = clusterv1alpha.NewForConfig(&configShallowCopy)
cs.databaseV1alpha, err = databasev1alpha.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
@ -85,7 +85,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) {
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *Clientset {
var cs Clientset
cs.clusterV1alpha = clusterv1alpha.NewForConfigOrDie(c)
cs.databaseV1alpha = databasev1alpha.NewForConfigOrDie(c)
cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
return &cs
@ -94,7 +94,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset {
// New creates a new Clientset for the given RESTClient.
func New(c rest.Interface) *Clientset {
var cs Clientset
cs.clusterV1alpha = clusterv1alpha.New(c)
cs.databaseV1alpha = databasev1alpha.New(c)
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
return &cs

View file

@ -21,8 +21,8 @@ package fake
import (
clientset "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned"
clusterv1alpha "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/typed/arangodb/v1alpha"
fakeclusterv1alpha "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/typed/arangodb/v1alpha/fake"
databasev1alpha "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/typed/arangodb/v1alpha"
fakedatabasev1alpha "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/typed/arangodb/v1alpha/fake"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/discovery"
@ -71,12 +71,12 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface {
var _ clientset.Interface = &Clientset{}
// ClusterV1alpha retrieves the ClusterV1alphaClient
func (c *Clientset) ClusterV1alpha() clusterv1alpha.ClusterV1alphaInterface {
return &fakeclusterv1alpha.FakeClusterV1alpha{Fake: &c.Fake}
// DatabaseV1alpha retrieves the DatabaseV1alphaClient
func (c *Clientset) DatabaseV1alpha() databasev1alpha.DatabaseV1alphaInterface {
return &fakedatabasev1alpha.FakeDatabaseV1alpha{Fake: &c.Fake}
}
// Cluster retrieves the ClusterV1alphaClient
func (c *Clientset) Cluster() clusterv1alpha.ClusterV1alphaInterface {
return &fakeclusterv1alpha.FakeClusterV1alpha{Fake: &c.Fake}
// Database retrieves the DatabaseV1alphaClient
func (c *Clientset) Database() databasev1alpha.DatabaseV1alphaInterface {
return &fakedatabasev1alpha.FakeDatabaseV1alpha{Fake: &c.Fake}
}

View file

@ -20,7 +20,7 @@
package fake
import (
clusterv1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
databasev1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
@ -51,5 +51,5 @@ func init() {
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
func AddToScheme(scheme *runtime.Scheme) {
clusterv1alpha.AddToScheme(scheme)
databasev1alpha.AddToScheme(scheme)
}

View file

@ -20,7 +20,7 @@
package scheme
import (
clusterv1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
databasev1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
@ -51,5 +51,5 @@ func init() {
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
func AddToScheme(scheme *runtime.Scheme) {
clusterv1alpha.AddToScheme(scheme)
databasev1alpha.AddToScheme(scheme)
}

View file

@ -1,175 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1alpha
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
scheme "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/scheme"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// ArangoClustersGetter has a method to return a ArangoClusterInterface.
// A group's client should implement this interface.
type ArangoClustersGetter interface {
ArangoClusters(namespace string) ArangoClusterInterface
}
// ArangoClusterInterface has methods to work with ArangoCluster resources.
type ArangoClusterInterface interface {
Create(*v1alpha.ArangoCluster) (*v1alpha.ArangoCluster, error)
Update(*v1alpha.ArangoCluster) (*v1alpha.ArangoCluster, error)
UpdateStatus(*v1alpha.ArangoCluster) (*v1alpha.ArangoCluster, error)
Delete(name string, options *v1.DeleteOptions) error
DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error
Get(name string, options v1.GetOptions) (*v1alpha.ArangoCluster, error)
List(opts v1.ListOptions) (*v1alpha.ArangoClusterList, error)
Watch(opts v1.ListOptions) (watch.Interface, error)
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha.ArangoCluster, err error)
ArangoClusterExpansion
}
// arangoClusters implements ArangoClusterInterface
type arangoClusters struct {
client rest.Interface
ns string
}
// newArangoClusters returns a ArangoClusters
func newArangoClusters(c *ClusterV1alphaClient, namespace string) *arangoClusters {
return &arangoClusters{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the arangoCluster, and returns the corresponding arangoCluster object, and an error if there is any.
func (c *arangoClusters) Get(name string, options v1.GetOptions) (result *v1alpha.ArangoCluster, err error) {
result = &v1alpha.ArangoCluster{}
err = c.client.Get().
Namespace(c.ns).
Resource("arangoclusters").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do().
Into(result)
return
}
// List takes label and field selectors, and returns the list of ArangoClusters that match those selectors.
func (c *arangoClusters) List(opts v1.ListOptions) (result *v1alpha.ArangoClusterList, err error) {
result = &v1alpha.ArangoClusterList{}
err = c.client.Get().
Namespace(c.ns).
Resource("arangoclusters").
VersionedParams(&opts, scheme.ParameterCodec).
Do().
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested arangoClusters.
func (c *arangoClusters) Watch(opts v1.ListOptions) (watch.Interface, error) {
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("arangoclusters").
VersionedParams(&opts, scheme.ParameterCodec).
Watch()
}
// Create takes the representation of a arangoCluster and creates it. Returns the server's representation of the arangoCluster, and an error, if there is any.
func (c *arangoClusters) Create(arangoCluster *v1alpha.ArangoCluster) (result *v1alpha.ArangoCluster, err error) {
result = &v1alpha.ArangoCluster{}
err = c.client.Post().
Namespace(c.ns).
Resource("arangoclusters").
Body(arangoCluster).
Do().
Into(result)
return
}
// Update takes the representation of a arangoCluster and updates it. Returns the server's representation of the arangoCluster, and an error, if there is any.
func (c *arangoClusters) Update(arangoCluster *v1alpha.ArangoCluster) (result *v1alpha.ArangoCluster, err error) {
result = &v1alpha.ArangoCluster{}
err = c.client.Put().
Namespace(c.ns).
Resource("arangoclusters").
Name(arangoCluster.Name).
Body(arangoCluster).
Do().
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *arangoClusters) UpdateStatus(arangoCluster *v1alpha.ArangoCluster) (result *v1alpha.ArangoCluster, err error) {
result = &v1alpha.ArangoCluster{}
err = c.client.Put().
Namespace(c.ns).
Resource("arangoclusters").
Name(arangoCluster.Name).
SubResource("status").
Body(arangoCluster).
Do().
Into(result)
return
}
// Delete takes name of the arangoCluster and deletes it. Returns an error if one occurs.
func (c *arangoClusters) Delete(name string, options *v1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("arangoclusters").
Name(name).
Body(options).
Do().
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *arangoClusters) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("arangoclusters").
VersionedParams(&listOptions, scheme.ParameterCodec).
Body(options).
Do().
Error()
}
// Patch applies the patch and returns the patched arangoCluster.
func (c *arangoClusters) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha.ArangoCluster, err error) {
result = &v1alpha.ArangoCluster{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("arangoclusters").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Into(result)
return
}

View file

@ -26,22 +26,22 @@ import (
rest "k8s.io/client-go/rest"
)
type ClusterV1alphaInterface interface {
type DatabaseV1alphaInterface interface {
RESTClient() rest.Interface
ArangoClustersGetter
ArangoDeploymentsGetter
}
// ClusterV1alphaClient is used to interact with features provided by the cluster.arangodb.com group.
type ClusterV1alphaClient struct {
// DatabaseV1alphaClient is used to interact with features provided by the database.arangodb.com group.
type DatabaseV1alphaClient struct {
restClient rest.Interface
}
func (c *ClusterV1alphaClient) ArangoClusters(namespace string) ArangoClusterInterface {
return newArangoClusters(c, namespace)
func (c *DatabaseV1alphaClient) ArangoDeployments(namespace string) ArangoDeploymentInterface {
return newArangoDeployments(c, namespace)
}
// NewForConfig creates a new ClusterV1alphaClient for the given config.
func NewForConfig(c *rest.Config) (*ClusterV1alphaClient, error) {
// NewForConfig creates a new DatabaseV1alphaClient for the given config.
func NewForConfig(c *rest.Config) (*DatabaseV1alphaClient, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
@ -50,12 +50,12 @@ func NewForConfig(c *rest.Config) (*ClusterV1alphaClient, error) {
if err != nil {
return nil, err
}
return &ClusterV1alphaClient{client}, nil
return &DatabaseV1alphaClient{client}, nil
}
// NewForConfigOrDie creates a new ClusterV1alphaClient for the given config and
// NewForConfigOrDie creates a new DatabaseV1alphaClient for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *ClusterV1alphaClient {
func NewForConfigOrDie(c *rest.Config) *DatabaseV1alphaClient {
client, err := NewForConfig(c)
if err != nil {
panic(err)
@ -63,9 +63,9 @@ func NewForConfigOrDie(c *rest.Config) *ClusterV1alphaClient {
return client
}
// New creates a new ClusterV1alphaClient for the given RESTClient.
func New(c rest.Interface) *ClusterV1alphaClient {
return &ClusterV1alphaClient{c}
// New creates a new DatabaseV1alphaClient for the given RESTClient.
func New(c rest.Interface) *DatabaseV1alphaClient {
return &DatabaseV1alphaClient{c}
}
func setConfigDefaults(config *rest.Config) error {
@ -83,7 +83,7 @@ func setConfigDefaults(config *rest.Config) error {
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *ClusterV1alphaClient) RESTClient() rest.Interface {
func (c *DatabaseV1alphaClient) RESTClient() rest.Interface {
if c == nil {
return nil
}

View file

@ -0,0 +1,175 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1alpha
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
scheme "github.com/arangodb/k8s-operator/pkg/generated/clientset/versioned/scheme"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// ArangoDeploymentsGetter has a method to return a ArangoDeploymentInterface.
// A group's client should implement this interface.
type ArangoDeploymentsGetter interface {
ArangoDeployments(namespace string) ArangoDeploymentInterface
}
// ArangoDeploymentInterface has methods to work with ArangoDeployment resources.
type ArangoDeploymentInterface interface {
Create(*v1alpha.ArangoDeployment) (*v1alpha.ArangoDeployment, error)
Update(*v1alpha.ArangoDeployment) (*v1alpha.ArangoDeployment, error)
UpdateStatus(*v1alpha.ArangoDeployment) (*v1alpha.ArangoDeployment, error)
Delete(name string, options *v1.DeleteOptions) error
DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error
Get(name string, options v1.GetOptions) (*v1alpha.ArangoDeployment, error)
List(opts v1.ListOptions) (*v1alpha.ArangoDeploymentList, error)
Watch(opts v1.ListOptions) (watch.Interface, error)
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha.ArangoDeployment, err error)
ArangoDeploymentExpansion
}
// arangoDeployments implements ArangoDeploymentInterface
type arangoDeployments struct {
client rest.Interface
ns string
}
// newArangoDeployments returns a ArangoDeployments
func newArangoDeployments(c *DatabaseV1alphaClient, namespace string) *arangoDeployments {
return &arangoDeployments{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the arangoDeployment, and returns the corresponding arangoDeployment object, and an error if there is any.
func (c *arangoDeployments) Get(name string, options v1.GetOptions) (result *v1alpha.ArangoDeployment, err error) {
result = &v1alpha.ArangoDeployment{}
err = c.client.Get().
Namespace(c.ns).
Resource("arangodeployments").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do().
Into(result)
return
}
// List takes label and field selectors, and returns the list of ArangoDeployments that match those selectors.
func (c *arangoDeployments) List(opts v1.ListOptions) (result *v1alpha.ArangoDeploymentList, err error) {
result = &v1alpha.ArangoDeploymentList{}
err = c.client.Get().
Namespace(c.ns).
Resource("arangodeployments").
VersionedParams(&opts, scheme.ParameterCodec).
Do().
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested arangoDeployments.
func (c *arangoDeployments) Watch(opts v1.ListOptions) (watch.Interface, error) {
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("arangodeployments").
VersionedParams(&opts, scheme.ParameterCodec).
Watch()
}
// Create takes the representation of a arangoDeployment and creates it. Returns the server's representation of the arangoDeployment, and an error, if there is any.
func (c *arangoDeployments) Create(arangoDeployment *v1alpha.ArangoDeployment) (result *v1alpha.ArangoDeployment, err error) {
result = &v1alpha.ArangoDeployment{}
err = c.client.Post().
Namespace(c.ns).
Resource("arangodeployments").
Body(arangoDeployment).
Do().
Into(result)
return
}
// Update takes the representation of a arangoDeployment and updates it. Returns the server's representation of the arangoDeployment, and an error, if there is any.
func (c *arangoDeployments) Update(arangoDeployment *v1alpha.ArangoDeployment) (result *v1alpha.ArangoDeployment, err error) {
result = &v1alpha.ArangoDeployment{}
err = c.client.Put().
Namespace(c.ns).
Resource("arangodeployments").
Name(arangoDeployment.Name).
Body(arangoDeployment).
Do().
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *arangoDeployments) UpdateStatus(arangoDeployment *v1alpha.ArangoDeployment) (result *v1alpha.ArangoDeployment, err error) {
result = &v1alpha.ArangoDeployment{}
err = c.client.Put().
Namespace(c.ns).
Resource("arangodeployments").
Name(arangoDeployment.Name).
SubResource("status").
Body(arangoDeployment).
Do().
Into(result)
return
}
// Delete takes name of the arangoDeployment and deletes it. Returns an error if one occurs.
func (c *arangoDeployments) Delete(name string, options *v1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("arangodeployments").
Name(name).
Body(options).
Do().
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *arangoDeployments) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("arangodeployments").
VersionedParams(&listOptions, scheme.ParameterCodec).
Body(options).
Do().
Error()
}
// Patch applies the patch and returns the patched arangoDeployment.
func (c *arangoDeployments) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha.ArangoDeployment, err error) {
result = &v1alpha.ArangoDeployment{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("arangodeployments").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Into(result)
return
}

View file

@ -1,141 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package fake
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
schema "k8s.io/apimachinery/pkg/runtime/schema"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
)
// FakeArangoClusters implements ArangoClusterInterface
type FakeArangoClusters struct {
Fake *FakeClusterV1alpha
ns string
}
var arangoclustersResource = schema.GroupVersionResource{Group: "cluster.arangodb.com", Version: "v1alpha", Resource: "arangoclusters"}
var arangoclustersKind = schema.GroupVersionKind{Group: "cluster.arangodb.com", Version: "v1alpha", Kind: "ArangoCluster"}
// Get takes name of the arangoCluster, and returns the corresponding arangoCluster object, and an error if there is any.
func (c *FakeArangoClusters) Get(name string, options v1.GetOptions) (result *v1alpha.ArangoCluster, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(arangoclustersResource, c.ns, name), &v1alpha.ArangoCluster{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoCluster), err
}
// List takes label and field selectors, and returns the list of ArangoClusters that match those selectors.
func (c *FakeArangoClusters) List(opts v1.ListOptions) (result *v1alpha.ArangoClusterList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(arangoclustersResource, arangoclustersKind, c.ns, opts), &v1alpha.ArangoClusterList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha.ArangoClusterList{}
for _, item := range obj.(*v1alpha.ArangoClusterList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested arangoClusters.
func (c *FakeArangoClusters) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(arangoclustersResource, c.ns, opts))
}
// Create takes the representation of a arangoCluster and creates it. Returns the server's representation of the arangoCluster, and an error, if there is any.
func (c *FakeArangoClusters) Create(arangoCluster *v1alpha.ArangoCluster) (result *v1alpha.ArangoCluster, err error) {
obj, err := c.Fake.
Invokes(testing.NewCreateAction(arangoclustersResource, c.ns, arangoCluster), &v1alpha.ArangoCluster{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoCluster), err
}
// Update takes the representation of a arangoCluster and updates it. Returns the server's representation of the arangoCluster, and an error, if there is any.
func (c *FakeArangoClusters) Update(arangoCluster *v1alpha.ArangoCluster) (result *v1alpha.ArangoCluster, err error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(arangoclustersResource, c.ns, arangoCluster), &v1alpha.ArangoCluster{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoCluster), err
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *FakeArangoClusters) UpdateStatus(arangoCluster *v1alpha.ArangoCluster) (*v1alpha.ArangoCluster, error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(arangoclustersResource, "status", c.ns, arangoCluster), &v1alpha.ArangoCluster{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoCluster), err
}
// Delete takes name of the arangoCluster and deletes it. Returns an error if one occurs.
func (c *FakeArangoClusters) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(arangoclustersResource, c.ns, name), &v1alpha.ArangoCluster{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeArangoClusters) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
action := testing.NewDeleteCollectionAction(arangoclustersResource, c.ns, listOptions)
_, err := c.Fake.Invokes(action, &v1alpha.ArangoClusterList{})
return err
}
// Patch applies the patch and returns the patched arangoCluster.
func (c *FakeArangoClusters) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha.ArangoCluster, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(arangoclustersResource, c.ns, name, data, subresources...), &v1alpha.ArangoCluster{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoCluster), err
}

View file

@ -25,17 +25,17 @@ import (
testing "k8s.io/client-go/testing"
)
type FakeClusterV1alpha struct {
type FakeDatabaseV1alpha struct {
*testing.Fake
}
func (c *FakeClusterV1alpha) ArangoClusters(namespace string) v1alpha.ArangoClusterInterface {
return &FakeArangoClusters{c, namespace}
func (c *FakeDatabaseV1alpha) ArangoDeployments(namespace string) v1alpha.ArangoDeploymentInterface {
return &FakeArangoDeployments{c, namespace}
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *FakeClusterV1alpha) RESTClient() rest.Interface {
func (c *FakeDatabaseV1alpha) RESTClient() rest.Interface {
var ret *rest.RESTClient
return ret
}

View file

@ -0,0 +1,141 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package fake
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
schema "k8s.io/apimachinery/pkg/runtime/schema"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
)
// FakeArangoDeployments implements ArangoDeploymentInterface
type FakeArangoDeployments struct {
Fake *FakeDatabaseV1alpha
ns string
}
var arangodeploymentsResource = schema.GroupVersionResource{Group: "database.arangodb.com", Version: "v1alpha", Resource: "arangodeployments"}
var arangodeploymentsKind = schema.GroupVersionKind{Group: "database.arangodb.com", Version: "v1alpha", Kind: "ArangoDeployment"}
// Get takes name of the arangoDeployment, and returns the corresponding arangoDeployment object, and an error if there is any.
func (c *FakeArangoDeployments) Get(name string, options v1.GetOptions) (result *v1alpha.ArangoDeployment, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(arangodeploymentsResource, c.ns, name), &v1alpha.ArangoDeployment{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoDeployment), err
}
// List takes label and field selectors, and returns the list of ArangoDeployments that match those selectors.
func (c *FakeArangoDeployments) List(opts v1.ListOptions) (result *v1alpha.ArangoDeploymentList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(arangodeploymentsResource, arangodeploymentsKind, c.ns, opts), &v1alpha.ArangoDeploymentList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha.ArangoDeploymentList{}
for _, item := range obj.(*v1alpha.ArangoDeploymentList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested arangoDeployments.
func (c *FakeArangoDeployments) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(arangodeploymentsResource, c.ns, opts))
}
// Create takes the representation of a arangoDeployment and creates it. Returns the server's representation of the arangoDeployment, and an error, if there is any.
func (c *FakeArangoDeployments) Create(arangoDeployment *v1alpha.ArangoDeployment) (result *v1alpha.ArangoDeployment, err error) {
obj, err := c.Fake.
Invokes(testing.NewCreateAction(arangodeploymentsResource, c.ns, arangoDeployment), &v1alpha.ArangoDeployment{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoDeployment), err
}
// Update takes the representation of a arangoDeployment and updates it. Returns the server's representation of the arangoDeployment, and an error, if there is any.
func (c *FakeArangoDeployments) Update(arangoDeployment *v1alpha.ArangoDeployment) (result *v1alpha.ArangoDeployment, err error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(arangodeploymentsResource, c.ns, arangoDeployment), &v1alpha.ArangoDeployment{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoDeployment), err
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *FakeArangoDeployments) UpdateStatus(arangoDeployment *v1alpha.ArangoDeployment) (*v1alpha.ArangoDeployment, error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(arangodeploymentsResource, "status", c.ns, arangoDeployment), &v1alpha.ArangoDeployment{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoDeployment), err
}
// Delete takes name of the arangoDeployment and deletes it. Returns an error if one occurs.
func (c *FakeArangoDeployments) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(arangodeploymentsResource, c.ns, name), &v1alpha.ArangoDeployment{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeArangoDeployments) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
action := testing.NewDeleteCollectionAction(arangodeploymentsResource, c.ns, listOptions)
_, err := c.Fake.Invokes(action, &v1alpha.ArangoDeploymentList{})
return err
}
// Patch applies the patch and returns the patched arangoDeployment.
func (c *FakeArangoDeployments) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha.ArangoDeployment, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(arangodeploymentsResource, c.ns, name, data, subresources...), &v1alpha.ArangoDeployment{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha.ArangoDeployment), err
}

View file

@ -19,4 +19,4 @@
//
package v1alpha
type ArangoClusterExpansion interface{}
type ArangoDeploymentExpansion interface{}

View file

@ -20,7 +20,7 @@
// This file was automatically generated by informer-gen
package cluster
package database
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/generated/informers/externalversions/arangodb/v1alpha"

View file

@ -35,59 +35,59 @@ import (
cache "k8s.io/client-go/tools/cache"
)
// ArangoClusterInformer provides access to a shared informer and lister for
// ArangoClusters.
type ArangoClusterInformer interface {
// ArangoDeploymentInformer provides access to a shared informer and lister for
// ArangoDeployments.
type ArangoDeploymentInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1alpha.ArangoClusterLister
Lister() v1alpha.ArangoDeploymentLister
}
type arangoClusterInformer struct {
type arangoDeploymentInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewArangoClusterInformer constructs a new informer for ArangoCluster type.
// NewArangoDeploymentInformer constructs a new informer for ArangoDeployment type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewArangoClusterInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredArangoClusterInformer(client, namespace, resyncPeriod, indexers, nil)
func NewArangoDeploymentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredArangoDeploymentInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredArangoClusterInformer constructs a new informer for ArangoCluster type.
// NewFilteredArangoDeploymentInformer constructs a new informer for ArangoDeployment type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewFilteredArangoClusterInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
func NewFilteredArangoDeploymentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ClusterV1alpha().ArangoClusters(namespace).List(options)
return client.DatabaseV1alpha().ArangoDeployments(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ClusterV1alpha().ArangoClusters(namespace).Watch(options)
return client.DatabaseV1alpha().ArangoDeployments(namespace).Watch(options)
},
},
&arangodb_v1alpha.ArangoCluster{},
&arangodb_v1alpha.ArangoDeployment{},
resyncPeriod,
indexers,
)
}
func (f *arangoClusterInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredArangoClusterInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
func (f *arangoDeploymentInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredArangoDeploymentInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *arangoClusterInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&arangodb_v1alpha.ArangoCluster{}, f.defaultInformer)
func (f *arangoDeploymentInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&arangodb_v1alpha.ArangoDeployment{}, f.defaultInformer)
}
func (f *arangoClusterInformer) Lister() v1alpha.ArangoClusterLister {
return v1alpha.NewArangoClusterLister(f.Informer().GetIndexer())
func (f *arangoDeploymentInformer) Lister() v1alpha.ArangoDeploymentLister {
return v1alpha.NewArangoDeploymentLister(f.Informer().GetIndexer())
}

View file

@ -28,8 +28,8 @@ import (
// Interface provides access to all the informers in this group version.
type Interface interface {
// ArangoClusters returns a ArangoClusterInformer.
ArangoClusters() ArangoClusterInformer
// ArangoDeployments returns a ArangoDeploymentInformer.
ArangoDeployments() ArangoDeploymentInformer
}
type version struct {
@ -43,7 +43,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList
return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
}
// ArangoClusters returns a ArangoClusterInformer.
func (v *version) ArangoClusters() ArangoClusterInformer {
return &arangoClusterInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
// ArangoDeployments returns a ArangoDeploymentInformer.
func (v *version) ArangoDeployments() ArangoDeploymentInformer {
return &arangoDeploymentInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}

View file

@ -127,9 +127,9 @@ type SharedInformerFactory interface {
ForResource(resource schema.GroupVersionResource) (GenericInformer, error)
WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
Cluster() arangodb.Interface
Database() arangodb.Interface
}
func (f *sharedInformerFactory) Cluster() arangodb.Interface {
func (f *sharedInformerFactory) Database() arangodb.Interface {
return arangodb.New(f, f.namespace, f.tweakListOptions)
}

View file

@ -56,9 +56,9 @@ func (f *genericInformer) Lister() cache.GenericLister {
// TODO extend this to unknown resources with a client pool
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
switch resource {
// Group=cluster.arangodb.com, Version=v1alpha
case v1alpha.SchemeGroupVersion.WithResource("arangoclusters"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Cluster().V1alpha().ArangoClusters().Informer()}, nil
// Group=database.arangodb.com, Version=v1alpha
case v1alpha.SchemeGroupVersion.WithResource("arangodeployments"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Database().V1alpha().ArangoDeployments().Informer()}, nil
}

View file

@ -1,98 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// This file was automatically generated by lister-gen
package v1alpha
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// ArangoClusterLister helps list ArangoClusters.
type ArangoClusterLister interface {
// List lists all ArangoClusters in the indexer.
List(selector labels.Selector) (ret []*v1alpha.ArangoCluster, err error)
// ArangoClusters returns an object that can list and get ArangoClusters.
ArangoClusters(namespace string) ArangoClusterNamespaceLister
ArangoClusterListerExpansion
}
// arangoClusterLister implements the ArangoClusterLister interface.
type arangoClusterLister struct {
indexer cache.Indexer
}
// NewArangoClusterLister returns a new ArangoClusterLister.
func NewArangoClusterLister(indexer cache.Indexer) ArangoClusterLister {
return &arangoClusterLister{indexer: indexer}
}
// List lists all ArangoClusters in the indexer.
func (s *arangoClusterLister) List(selector labels.Selector) (ret []*v1alpha.ArangoCluster, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha.ArangoCluster))
})
return ret, err
}
// ArangoClusters returns an object that can list and get ArangoClusters.
func (s *arangoClusterLister) ArangoClusters(namespace string) ArangoClusterNamespaceLister {
return arangoClusterNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// ArangoClusterNamespaceLister helps list and get ArangoClusters.
type ArangoClusterNamespaceLister interface {
// List lists all ArangoClusters in the indexer for a given namespace.
List(selector labels.Selector) (ret []*v1alpha.ArangoCluster, err error)
// Get retrieves the ArangoCluster from the indexer for a given namespace and name.
Get(name string) (*v1alpha.ArangoCluster, error)
ArangoClusterNamespaceListerExpansion
}
// arangoClusterNamespaceLister implements the ArangoClusterNamespaceLister
// interface.
type arangoClusterNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all ArangoClusters in the indexer for a given namespace.
func (s arangoClusterNamespaceLister) List(selector labels.Selector) (ret []*v1alpha.ArangoCluster, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha.ArangoCluster))
})
return ret, err
}
// Get retrieves the ArangoCluster from the indexer for a given namespace and name.
func (s arangoClusterNamespaceLister) Get(name string) (*v1alpha.ArangoCluster, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1alpha.Resource("arangocluster"), name)
}
return obj.(*v1alpha.ArangoCluster), nil
}

View file

@ -0,0 +1,98 @@
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// This file was automatically generated by lister-gen
package v1alpha
import (
v1alpha "github.com/arangodb/k8s-operator/pkg/apis/arangodb/v1alpha"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// ArangoDeploymentLister helps list ArangoDeployments.
type ArangoDeploymentLister interface {
// List lists all ArangoDeployments in the indexer.
List(selector labels.Selector) (ret []*v1alpha.ArangoDeployment, err error)
// ArangoDeployments returns an object that can list and get ArangoDeployments.
ArangoDeployments(namespace string) ArangoDeploymentNamespaceLister
ArangoDeploymentListerExpansion
}
// arangoDeploymentLister implements the ArangoDeploymentLister interface.
type arangoDeploymentLister struct {
indexer cache.Indexer
}
// NewArangoDeploymentLister returns a new ArangoDeploymentLister.
func NewArangoDeploymentLister(indexer cache.Indexer) ArangoDeploymentLister {
return &arangoDeploymentLister{indexer: indexer}
}
// List lists all ArangoDeployments in the indexer.
func (s *arangoDeploymentLister) List(selector labels.Selector) (ret []*v1alpha.ArangoDeployment, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha.ArangoDeployment))
})
return ret, err
}
// ArangoDeployments returns an object that can list and get ArangoDeployments.
func (s *arangoDeploymentLister) ArangoDeployments(namespace string) ArangoDeploymentNamespaceLister {
return arangoDeploymentNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// ArangoDeploymentNamespaceLister helps list and get ArangoDeployments.
type ArangoDeploymentNamespaceLister interface {
// List lists all ArangoDeployments in the indexer for a given namespace.
List(selector labels.Selector) (ret []*v1alpha.ArangoDeployment, err error)
// Get retrieves the ArangoDeployment from the indexer for a given namespace and name.
Get(name string) (*v1alpha.ArangoDeployment, error)
ArangoDeploymentNamespaceListerExpansion
}
// arangoDeploymentNamespaceLister implements the ArangoDeploymentNamespaceLister
// interface.
type arangoDeploymentNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all ArangoDeployments in the indexer for a given namespace.
func (s arangoDeploymentNamespaceLister) List(selector labels.Selector) (ret []*v1alpha.ArangoDeployment, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha.ArangoDeployment))
})
return ret, err
}
// Get retrieves the ArangoDeployment from the indexer for a given namespace and name.
func (s arangoDeploymentNamespaceLister) Get(name string) (*v1alpha.ArangoDeployment, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1alpha.Resource("arangodeployment"), name)
}
return obj.(*v1alpha.ArangoDeployment), nil
}

View file

@ -22,10 +22,10 @@
package v1alpha
// ArangoClusterListerExpansion allows custom methods to be added to
// ArangoClusterLister.
type ArangoClusterListerExpansion interface{}
// ArangoDeploymentListerExpansion allows custom methods to be added to
// ArangoDeploymentLister.
type ArangoDeploymentListerExpansion interface{}
// ArangoClusterNamespaceListerExpansion allows custom methods to be added to
// ArangoClusterNamespaceLister.
type ArangoClusterNamespaceListerExpansion interface{}
// ArangoDeploymentNamespaceListerExpansion allows custom methods to be added to
// ArangoDeploymentNamespaceLister.
type ArangoDeploymentNamespaceListerExpansion interface{}