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

Add ReplicatedMap CR #394

Merged
merged 4 commits into from Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -152,7 +152,7 @@ test-it-focus: manifests generate fmt vet ## Run tests.
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); PHONE_HOME_ENABLED=$(PHONE_HOME_ENABLED) DEVELOPER_MODE_ENABLED=$(DEVELOPER_MODE_ENABLED) go test -tags $(GO_BUILD_TAGS) -v ./test/integration/... -coverprofile cover.out $(GO_TEST_FLAGS) -timeout 5m

E2E_TEST_SUITE ?= hz || mc || hz_persistence || hz_expose_externally || map || map_persistence || hz_wan || custom_class || multimap || topic
E2E_TEST_SUITE ?= hz || mc || hz_persistence || hz_expose_externally || map || map_persistence || hz_wan || custom_class || multimap || topic || replicatedmap
ifeq (,$(E2E_TEST_SUITE))
E2E_TEST_LABELS =
else
Expand Down
8 changes: 8 additions & 0 deletions PROJECT
Expand Up @@ -61,4 +61,12 @@ resources:
kind: Topic
path: github.com/hazelcast/hazelcast-platform-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: hazelcast.com
kind: ReplicatedMap
path: github.com/hazelcast/hazelcast-platform-operator/api/v1alpha1
version: v1alpha1
version: "3"
2 changes: 1 addition & 1 deletion Tiltfile
Expand Up @@ -57,7 +57,7 @@ cmd_button('Undeploy operator',
)

cmd_button('Delete CRs and PVCs',
argv=['sh', '-c', '(kubectl delete $(kubectl get wanreplication,hotbackup,map,multimap,topic,hazelcast,managementcenter -o name) 2> /dev/null || echo "No CRs" ) && kubectl delete pvc -l "app.kubernetes.io/managed-by=hazelcast-platform-operator"'],
argv=['sh', '-c', '(kubectl delete $(kubectl get wanreplication,hotbackup,map,multimap,topic,replicatedmap,hazelcast,managementcenter -o name) 2> /dev/null || echo "No CRs" ) && kubectl delete pvc -l "app.kubernetes.io/managed-by=hazelcast-platform-operator"'],
resource='hazelcast-platform-controller-manager',
location=location.RESOURCE,
icon_name='delete',
Expand Down
116 changes: 116 additions & 0 deletions api/v1alpha1/replicatedmap_types.go
@@ -0,0 +1,116 @@
package v1alpha1

import (
"encoding/json"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// ReplicatedMapSpec defines the desired state of ReplicatedMap
type ReplicatedMapSpec struct {
// Name of the ReplicatedMap config to be created. If empty, CR name will be used.
// +optional
Name string `json:"name,omitempty"`

// AsyncFillup specifies whether the ReplicatedMap is available for reads before the initial replication is completed
// +kubebuilder:default:=true
// +optional
AsyncFillup bool `json:"asyncFillup,omitempty"`

// InMemoryFormat specifies in which format data will be stored in the ReplicatedMap
// +kubebuilder:default:=OBJECT
// +optional
InMemoryFormat InMemoryFormatType `json:"inMemoryFormat,omitempty"`

// HazelcastResourceName defines the name of the Hazelcast resource.
// +kubebuilder:validation:MinLength:=1
HazelcastResourceName string `json:"hazelcastResourceName"`
}

// ReplicatedMapStatus defines the observed state of ReplicatedMap
type ReplicatedMapStatus struct {
State DataStructureConfigState `json:"state,omitempty"`
Message string `json:"message,omitempty"`
MemberStatuses map[string]DataStructureConfigState `json:"memberStatuses,omitempty"`
}

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

// ReplicatedMap is the Schema for the replicatedmaps API
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.state",description="Current state of the ReplicatedMap Config"
// +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.message",description="Message for the current ReplicatedMap Config"
// +kubebuilder:resource:shortName=rmap
type ReplicatedMap struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ReplicatedMapSpec `json:"spec,omitempty"`
Status ReplicatedMapStatus `json:"status,omitempty"`
}

func (mm *ReplicatedMap) GetDSName() string {
if mm.Spec.Name != "" {
return mm.Spec.Name
}
return mm.Name
}

func (mm *ReplicatedMap) GetKind() string {
return mm.Kind
}

func (mm *ReplicatedMap) GetHZResourceName() string {
return mm.Spec.HazelcastResourceName
}

func (mm *ReplicatedMap) GetStatus() DataStructureConfigState {
return mm.Status.State
}

func (mm *ReplicatedMap) GetMemberStatuses() map[string]DataStructureConfigState {
return mm.Status.MemberStatuses
}

func (mm *ReplicatedMap) SetStatus(status DataStructureConfigState, msg string, memberStatues map[string]DataStructureConfigState) {
mm.Status.State = status
mm.Status.Message = msg
mm.Status.MemberStatuses = memberStatues
}

func (mm *ReplicatedMap) GetSpec() (string, error) {
mms, err := json.Marshal(mm.Spec)
if err != nil {
return "", fmt.Errorf("error marshaling %v as JSON: %w", mm.Kind, err)
}
return string(mms), nil
}

func (mm *ReplicatedMap) SetSpec(spec string) error {
if err := json.Unmarshal([]byte(spec), &mm.Spec); err != nil {
return err
}
return nil
}

//+kubebuilder:object:root=true

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

func (rml *ReplicatedMapList) GetItems() []client.Object {
l := make([]client.Object, 0, len(rml.Items))
for _, item := range rml.Items {
l = append(l, client.Object(&item))
}
return l
}

func init() {
SchemeBuilder.Register(&ReplicatedMap{}, &ReplicatedMapList{})
}
96 changes: 96 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

135 changes: 135 additions & 0 deletions bundle.yaml
Expand Up @@ -2806,6 +2806,115 @@ status:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: replicatedmaps.hazelcast.com
spec:
group: hazelcast.com
names:
kind: ReplicatedMap
listKind: ReplicatedMapList
plural: replicatedmaps
shortNames:
- rmap
singular: replicatedmap
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: Current state of the ReplicatedMap Config
jsonPath: .status.state
name: Status
type: string
- description: Message for the current ReplicatedMap Config
jsonPath: .status.message
name: Message
priority: 1
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: ReplicatedMap is the Schema for the replicatedmaps API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ReplicatedMapSpec defines the desired state of ReplicatedMap
properties:
asyncFillup:
default: true
description: AsyncFillup specifies whether the ReplicatedMap is available
for reads before the initial replication is completed
type: boolean
hazelcastResourceName:
description: HazelcastResourceName defines the name of the Hazelcast
resource.
minLength: 1
type: string
inMemoryFormat:
default: OBJECT
description: InMemoryFormat specifies in which format data will be
stored in the ReplicatedMap
enum:
- BINARY
- OBJECT
type: string
name:
description: Name of the ReplicatedMap config to be created. If empty,
CR name will be used.
type: string
required:
- hazelcastResourceName
type: object
status:
description: ReplicatedMapStatus defines the observed state of ReplicatedMap
properties:
memberStatuses:
additionalProperties:
enum:
- Success
- Failed
- Pending
- Persisting
- Terminating
type: string
type: object
message:
type: string
state:
enum:
- Success
- Failed
- Pending
- Persisting
- Terminating
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
Expand Down Expand Up @@ -3343,6 +3452,32 @@ rules:
- get
- patch
- update
- apiGroups:
- hazelcast.com
resources:
- replicatedmaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- hazelcast.com
resources:
- replicatedmaps/finalizers
verbs:
- update
- apiGroups:
- hazelcast.com
resources:
- replicatedmaps/status
verbs:
- get
- patch
- update
- apiGroups:
- hazelcast.com
resources:
Expand Down