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/discovery deployment #58

Draft
wants to merge 14 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
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ COPY go.sum go.sum
RUN export GOPROXY=https://goproxy.io/ && go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY cmd/operator/main.go cmd/operator/main.go
COPY cmd/discovery/main.go cmd/discovery/main.go
COPY api/ api/
COPY internal/ internal/

Expand All @@ -21,14 +22,16 @@ COPY internal/ internal/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/operator/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o discovery cmd/discovery/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
# FROM gcr.io/distroless/static:nonroot
FROM kubeimages/distroless-static:latest
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/discovery .
USER 65532:65532

ENTRYPOINT ["/manager"]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= ghcr.io/xline-kv/xline-operator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0

Expand Down Expand Up @@ -84,11 +84,12 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
go build -o bin/manager cmd/operator/main.go
go build -o bin/discovery cmd/discovery/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
go run ./cmd/operator/main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ my-xline-cluster -
# Get Xline pod
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-xline-cluster-sts-0 1/1 Running 0 -
my-xline-cluster-sts-1 1/1 Running 0 -
my-xline-cluster-sts-2 1/1 Running 0 -
my-xline-cluster-0 1/1 Running 0 -
my-xline-cluster-1 1/1 Running 0 -
my-xline-cluster-2 1/1 Running 0 -
```

### Delete the xline cluster
Expand Down
147 changes: 84 additions & 63 deletions api/v1alpha1/xlinecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,65 +51,65 @@ type XlineClusterList struct {
}

type XlineArgs struct {
JaegerOffline bool `json:"jaeger-offline,omitempty"`
JaegerOnline bool `json:"jaeger-online,omitempty"`
JaegerLevel bool `json:"jaeger-level,omitempty"`
ClientUseBackoff bool `json:"client-use-backoff,omitempty"`
AuthPrivateKey *string `json:"auth-private-key,omitempty"`
AuthPublicKey *string `json:"auth-public-key,omitempty"`
JaegerOutputDir *string `json:"jaeger-output-dir,omitempty"`
LogFile *string `json:"log-file,omitempty"`
LogRotate *string `json:"log-rotate,omitempty"`

// +kubebuilder:validation:Enum=off;info;error;warn;trace;debug
LogLevel *string `json:"log-level,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
HeartbeatInterval *string `json:"heartbeat-interval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
ServerWaitSyncedTimeout *string `json:"server-wait-synced-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
RetryTimeout *string `json:"retry-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
RpcTimeout *string `json:"rpc-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
BatchTimeout *string `json:"batch-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
ClientWaitSyncedTimeout *string `json:"client-wait-synced-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
ClientProposeTimeout *string `json:"client-propose-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
ClientInitialRetryTimeout *string `json:"client-initial-retry-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
ClientMaxRetryTimeout *string `json:"client-max-retry-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
GcInterval *string `json:"gc-interval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
RangeRetryTimeout *string `json:"range-retry-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
CompactTimeout *string `json:"compact-timeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
SyncVictimsInterval *string `json:"sync-victims-interval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
WatchProgressNotifyInterval *string `json:"watch-progress-notify-interval,omitempty"`
CurpDir *string `json:"curp-dir,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s|m|h|d)
CompactSleepInterval *string `json:"compact-sleep-interval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(B|MB|GB)
BatchMaxSize *string `json:"batch-max-size,omitempty"`
JaegerOffline bool `json:"JaegerOffline,omitempty"`
JaegerOnline bool `json:"JaegerOnline,omitempty"`
ClientUseBackoff bool `json:"ClientUseBackoff,omitempty"`
JaegerLevel *string `json:"JaegerLevel,omitempty"`
JaegerOutputDir *string `json:"JaegerOutputDir,omitempty"`
LogFile *string `json:"LogFile,omitempty"`

// +kubebuilder:validation:Enum=never;hourly;daily
LogRotate *string `json:"LogRotate,omitempty"`

// +kubebuilder:validation:Enum=trace;debug;info;warn;error
LogLevel *string `json:"LogLevel,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms)
HeartbeatInterval *string `json:"HeartbeatInterval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(ms|s)
ServerWaitSyncedTimeout *string `json:"ServerWaitSyncedTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(ms|s)
RetryTimeout *string `json:"RetryTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
RpcTimeout *string `json:"RpcTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
BatchTimeout *string `json:"BatchTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
ClientWaitSyncedTimeout *string `json:"ClientWaitSyncedTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
ClientProposeTimeout *string `json:"ClientProposeTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
ClientInitialRetryTimeout *string `json:"ClientInitialRetryTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
ClientMaxRetryTimeout *string `json:"ClientMaxRetryTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
GcInterval *string `json:"GcInterval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
RangeRetryTimeout *string `json:"RangeRetryTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
CompactTimeout *string `json:"CompactTimeout,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
SyncVictimsInterval *string `json:"SyncVictimsInterval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
WatchProgressNotifyInterval *string `json:"WatchProgressNotifyInterval,omitempty"`
CurpDir *string `json:"CurpDir,omitempty"`
// +kubebuilder:validation:Pattern=\d+(us|ms|s)
CompactSleepInterval *string `json:"CompactSleepInterval,omitempty"`
// +kubebuilder:validation:Pattern=\d+(KB|MB|kb|mb)
BatchMaxSize *string `json:"BatchMaxSize,omitempty"`
// +kubebuilder:validation:Minimum=1
RetryCount int `json:"retry-count,omitempty"`
RetryCount int `json:"RetryCount,omitempty"`
// +kubebuilder:validation:Minimum=1
FollowerTimeoutTicks int `json:"follower-timeout-ticks,omitempty"`
FollowerTimeoutTicks int `json:"FollowerTimeoutTicks,omitempty"`
// +kubebuilder:validation:Minimum=1
CandidateTimeoutTicks int `json:"candidate-timeout-ticks,omitempty"`
CandidateTimeoutTicks int `json:"CandidateTimeoutTicks,omitempty"`
// +kubebuilder:validation:Minimum=1
LogEntriesCap int `json:"log-entries-cap,omitempty"`
LogEntriesCap int `json:"LogEntriesCap,omitempty"`
// +kubebuilder:validation:Minimum=1
CmdWorkers int `json:"cmd-workers,omitempty"`
CmdWorkers int `json:"CmdWorkers,omitempty"`
// +kubebuilder:validation:Minimum=1
CompactBatchSize int `json:"compact-batch-size,omitempty"`
CompactBatchSize int `json:"CompactBatchSize,omitempty"`
// +kubebuilder:validation:Minimum=1
Quota int `json:"quota,omitempty"`
Quota int `json:"Quota,omitempty"`
}

// ########################################
Expand All @@ -124,7 +124,7 @@ type XlineClusterSpec struct {

/// Xline container bootstrap arguments
/// Set additional arguments except [`--name`, `--members`, `--storage-engine`, `--data-dir`]
BootstrapArgs XlineArgs `json:"bootstrapArgs,omitempty"`
BootstrapArgs *XlineArgs `json:"config,omitempty"`

// ImagePullPolicy of Xline cluster Pods
// +optional
Expand All @@ -133,11 +133,29 @@ type XlineClusterSpec struct {
// The replicas of xline nodes
// +kubebuilder:validation:Minimum=3
Replicas int32 `json:"replicas"`

// The auth secret keys
AuthSecrets *XlineAuthSecret `json:"authSecret,omitempty"`

// K8s storage-class-name of the Xline storage
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName"`

// Defines the specification of resource cpu, mem, storage.
corev1.ResourceRequirements `json:",inline"`
}

type XlineAuthSecret struct {
Name *string `json:"name"`
MountPath *string `json:"mountPath"`
PubKey *string `json:"pubKey"`
PriKey *string `json:"priKey"`
}

func (s *XlineClusterSpec) BootArgs() []string {
func (s *XlineClusterSpec) BootArgs() map[string]string {
bytes, err := json.Marshal(s.BootstrapArgs)
args := make([]string, 0)
args := map[string]string{}
if err != nil {
return args
}
Expand All @@ -146,11 +164,7 @@ func (s *XlineClusterSpec) BootArgs() []string {
return args
}
for k, v := range data {
if bv, ok := v.(bool); ok && bv {
args = append(args, fmt.Sprintf("--%s", k))
continue
}
args = append(args, fmt.Sprintf("--%s", k), fmt.Sprintf("%v", v))
args[k] = fmt.Sprintf("%v", v)
}
return args
}
Expand All @@ -166,9 +180,16 @@ type XlineClusterStatus struct {
type XlineClusterOprStage string

const (
StageXlineService XlineClusterOprStage = "Xline/Service"
StageXlineStatefulSet XlineClusterOprStage = "Xline/Statefulset"
StageComplete XlineClusterOprStage = "complete"
StageXlineScriptCM XlineClusterOprStage = "Xline/ScriptCM"
StageXlineConfigMap XlineClusterOprStage = "Xline/ConfigMap"
StageXlineService XlineClusterOprStage = "Xline/Service"
StageXlineDiscoveryService XlineClusterOprStage = "Xline/DiscoveryService"
StageXlineDiscoverySA XlineClusterOprStage = "Xline/DiscoverySA"
StageXlineDiscoveryRole XlineClusterOprStage = "Xline/DiscoveryRole"
StageXlineDiscoveryRoleBinding XlineClusterOprStage = "Xline/DiscoveryRoleBinding"
StageXlineDiscoveryDeploy XlineClusterOprStage = "Xline/DiscoveryDeploy"
StageXlineStatefulSet XlineClusterOprStage = "Xline/Statefulset"
StageComplete XlineClusterOprStage = "complete"
)

// XlineClusterRecStatus represents XlineCluster reconcile status
Expand Down
63 changes: 54 additions & 9 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading
Loading