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

Feat/deploy basic #46

Merged
merged 10 commits into from
Jan 14, 2024
59 changes: 59 additions & 0 deletions api/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2023.

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 "k8s.io/apimachinery/pkg/types"

// NamespacedName is the name and namespace of the kubernetes object
// +k8s:openapi-gen=true
type NamespacedName struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

func NewNamespacedName(name types.NamespacedName) NamespacedName {
return NamespacedName{
Name: name.Name,
Namespace: name.Namespace,
}
}

// OprStageAction represents the action type of controller reconcile stage
type OprStageAction string

const (
StageActionApply OprStageAction = "apply"
StageActionDelete OprStageAction = "delete"
)

// OprStageStatus represents the status of controller stage
type OprStageStatus string

const (
StageResultSucceeded OprStageStatus = "succeeded"
StageResultFailed OprStageStatus = "failed"
)

func (e *XlineCluster) ObjKey() types.NamespacedName {
if e.objKey == nil {
key := types.NamespacedName{Namespace: e.Namespace, Name: e.Name}
e.objKey = &key
return key
} else {
return *e.objKey
}
}
20 changes: 20 additions & 0 deletions api/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

func TestObjKey(t *testing.T) {
xlineCluster := XlineCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "xline",
Namespace: "default",
},
}
expected_objkey := types.NamespacedName{Name: "xline", Namespace: "default"}
assert.Equal(t, xlineCluster.ObjKey(), expected_objkey)
}
82 changes: 60 additions & 22 deletions api/v1alpha1/xlinecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,84 @@ limitations under the License.
package v1alpha1

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

// 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.

// XlineCluster is the Schema for the xlineclusters API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=xc

type XlineCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec XlineClusterSpec `json:"spec,omitempty"`
Status XlineClusterStatus `json:"status,omitempty"`
objKey *types.NamespacedName `json:"-"`
}

// XlineClusterList contains a list of XlineCluster
// +kubebuilder:object:root=true
type XlineClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []XlineCluster `json:"items"`
}

// ########################################
// XlineClusterSpec
// ########################################

// XlineClusterSpec defines the desired state of XlineCluster
// +k8s:openapi-gen=true
type XlineClusterSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Xline cluster image
Image *string `json:"image,omitempty"`

// Foo is an example field of XlineCluster. Edit xlinecluster_types.go to remove/update
Foo string `json:"foo,omitempty"`
// ImagePullPolicy of Xline cluster Pods
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// The replicas of xline nodes
// +kubebuilder:validation:Minimum=3
Replicas int32 `json:"replicas"`
}

// XlineClusterStatus defines the observed state of XlineCluster
type XlineClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
LastApplySpecHash *string `json:"lastApplySpecHash,omitempty"`
XlineClusterRecStatus `json:",inline"`
XlineClusterSyncStatus `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// XlineClusterOprStage represents XlineCluster operator stage
type XlineClusterOprStage string

// XlineCluster is the Schema for the xlineclusters API
type XlineCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
const (
StageXlineService XlineClusterOprStage = "Xline/Service"
StageXlineStatefulSet XlineClusterOprStage = "Xline/Statefulset"
StageComplete XlineClusterOprStage = "complete"
)

Spec XlineClusterSpec `json:"spec,omitempty"`
Status XlineClusterStatus `json:"status,omitempty"`
// XlineClusterRecStatus represents XlineCluster reconcile status
type XlineClusterRecStatus struct {
Stage XlineClusterOprStage `json:"stage,omitempty"`
StageStatus OprStageStatus `json:"stageStatus,omitempty"`
LastMessage string `json:"lastMessage,omitempty"`
}

//+kubebuilder:object:root=true

// XlineClusterList contains a list of XlineCluster
type XlineClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []XlineCluster `json:"items"`
// XlineClusterSyncStatus represents XlineCluster sync status
type XlineClusterSyncStatus struct {
Image string `json:"image,omitempty"`
StatefulSetRef NamespacedName `json:"statefulSetRef,omitempty"`
ServiceRef NamespacedName `json:"serviceRef,omitempty"`
Conditions []appv1.StatefulSetCondition `json:"conditions,omitempty"`
}

func init() {
Expand Down
77 changes: 75 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

xlinekvstoredatenlordcomv1alpha1 "github.com/xline-kv/xline-operator/api/v1alpha1"
xapi "github.com/xline-kv/xline-operator/api/v1alpha1"
"github.com/xline-kv/xline-operator/internal/controller"
//+kubebuilder:scaffold:imports
)
Expand All @@ -45,7 +45,7 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(xlinekvstoredatenlordcomv1alpha1.AddToScheme(scheme))
utilruntime.Must(xapi.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down
Loading
Loading