Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigMap replication (with non-typed replication) #509

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ ifdef TEST
@echo Running test $(TEST)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(GO_FLAGS) ./apis/... ./pkg/... ./test/yq/... ./controllers/... -run="$(TEST)" -coverprofile cover.out
else
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(GO_FLAGS) ./apis/... ./pkg/... ./test/yq/... ./controllers/... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -run ^TestConfigMapController$ $(GO_FLAGS) ./controllers/replication/... -coverprofile cover.out
# KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(GO_FLAGS) ./apis/... ./pkg/... ./test/yq/... ./controllers/... -coverprofile cover.out
endif

PHONY: e2e-test
Expand Down
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ resources:
kind: ReplicatedSecret
path: github.com/k8ssandra/k8ssandra-operator/apis/replication/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: k8ssandra.io
group: replication
kind: ReplicatedConfigMap
path: github.com/k8ssandra/k8ssandra-operator/apis/replication/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
Expand Down
2 changes: 1 addition & 1 deletion apis/config/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/medusa/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/reaper/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions apis/replication/v1alpha1/replicatedconfigmap_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2021.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ReplicatedConfigMapSpec defines the desired state of ReplicatedConfigMap
type ReplicatedConfigMapSpec struct {
*ReplicatedResourceSpec `json:",inline"`
}

// ReplicatedConfigMapStatus defines the observed state of ReplicatedConfigMap
type ReplicatedConfigMapStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +optional
Conditions []ReplicationCondition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ReplicatedConfigMap is the Schema for the ReplicatedConfigMaps API
type ReplicatedConfigMap struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ReplicatedConfigMapSpec `json:"spec,omitempty"`
Status ReplicatedConfigMapStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ReplicatedConfigMapList contains a list of ReplicatedConfigMap
type ReplicatedConfigMapList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ReplicatedConfigMap `json:"items"`
}

func init() {
SchemeBuilder.Register(&ReplicatedConfigMap{}, &ReplicatedConfigMapList{})
}
59 changes: 59 additions & 0 deletions apis/replication/v1alpha1/replicatedresource_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// type ReplicatedResource interface {
// ReplicationTargets() []ReplicationTarget
// Selector() *metav1.LabelSelector
// }

type ReplicatedResourceSpec struct {
// TODO Add Kind + ApiVersion?

// Selector defines which secrets are replicated. If left empty, all the secrets are replicated
// +optional
Selector *metav1.LabelSelector `json:"selector,omitempty"`
// TargetContexts indicates the target clusters to which the secrets are replicated to. If empty, no clusters are targeted
// +optional
ReplicationTargets []ReplicationTarget `json:"replicationTargets,omitempty"`
}

type ReplicationTarget struct {
// TODO Implement at some point
// Namespace to replicate the data to in the target cluster. If left empty, current namespace is used.
// +optional
Namespace string `json:"namespace,omitempty"`

// K8sContextName defines the target cluster name as set in the ClientConfig. If left empty, current cluster is assumed
// +optional
K8sContextName string `json:"k8sContextName,omitempty"`

// TODO Add label selector for clusters (from ClientConfigs)
// Selector defines which clusters are targeted.
// +optional
// Selector *metav1.LabelSelector `json:"selector,omitempty"`
}

type ReplicationConditionType string

const (
ReplicationDone ReplicationConditionType = "Replication"
)

type ReplicationCondition struct {
// Cluster
Cluster string `json:"cluster"`

// Type of condition
Type ReplicationConditionType `json:"type"`

// Status of the replication to target cluster
Status corev1.ConditionStatus `json:"status"`

// LastTransitionTime is the last time the condition transited from one status to another.
// +optional
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
}
68 changes: 18 additions & 50 deletions apis/replication/v1alpha1/replicatedsecret_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,40 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// var _ ReplicatedResource = &ReplicatedSecretSpec{}

// type ReplicatedResource interface {
// *ReplicatedResourceSpec
// }

// ReplicatedSecretSpec defines the desired state of ReplicatedSecret
type ReplicatedSecretSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Selector defines which secrets are replicated. If left empty, all the secrets are replicated
// +optional
Selector *metav1.LabelSelector `json:"selector,omitempty"`
// TargetContexts indicates the target clusters to which the secrets are replicated to. If empty, no clusters are targeted
// +optional
ReplicationTargets []ReplicationTarget `json:"replicationTargets,omitempty"`
*ReplicatedResourceSpec `json:",inline"`
// // Selector defines which secrets are replicated. If left empty, all the secrets are replicated
// // +optional
// Selector *metav1.LabelSelector `json:"selector,omitempty"`
// // TargetContexts indicates the target clusters to which the secrets are replicated to. If empty, no clusters are targeted
// // +optional
// ReplicationTargets []ReplicationTarget `json:"replicationTargets,omitempty"`
}

type ReplicationTarget struct {
// TODO Implement at some point
// Namespace to replicate the data to in the target cluster. If left empty, current namespace is used.
// +optional
Namespace string `json:"namespace,omitempty"`
// func (r *ReplicatedSecretSpec) ReplicationTargets() []ReplicationTarget {
// return r.ReplicationTargets
// }

// K8sContextName defines the target cluster name as set in the ClientConfig. If left empty, current cluster is assumed
// +optional
K8sContextName string `json:"k8sContextName,omitempty"`

// TODO Add label selector for clusters (from ClientConfigs)
// Selector defines which clusters are targeted.
// +optional
// Selector *metav1.LabelSelector `json:"selector,omitempty"`
}
// func (r *ReplicatedSecretSpec) Selector() *metav1.LabelSelector {
// return r.Selector
// }

// ReplicatedSecretStatus defines the observed state of ReplicatedSecret
type ReplicatedSecretStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +optional
Conditions []ReplicationCondition `json:"conditions,omitempty"`
}

type ReplicationConditionType string

const (
ReplicationDone ReplicationConditionType = "Replication"
)

type ReplicationCondition struct {
// Cluster
Cluster string `json:"cluster"`

// Type of condition
Type ReplicationConditionType `json:"type"`

// Status of the replication to target cluster
Status corev1.ConditionStatus `json:"status"`

// LastTransitionTime is the last time the condition transited from one status to another.
// +optional
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
Loading