diff --git a/CHANGELOG.md b/CHANGELOG.md index 302061da3..b0a3d8f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - (Feature) Add RestartPolicyAlways to ArangoDeployment in order to restart ArangoDB on failure - (Feature) Set a leader in active fail-over mode - (Feature) Use policy/v1 instead policy/v1beta1 +- (Feature) OPS CLI with Arango Task ## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07) - (Bugfix) Fix arangosync members state inspection diff --git a/Dockerfile b/Dockerfile index 095e7c5fe..ea8a4b6ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,5 +15,6 @@ ADD ./LICENSE /licenses/LICENSE ARG RELEASE_MODE=community ARG TARGETARCH ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator /usr/bin/arangodb_operator +ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator_ops /usr/bin/arangodb_operator_ops ENTRYPOINT [ "/usr/bin/arangodb_operator" ] diff --git a/Dockerfile.debug b/Dockerfile.debug index d194a5b90..08f49c328 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -25,6 +25,7 @@ RUN apk add --no-cache libc6-compat ADD ./LICENSE /licenses/LICENSE ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator /usr/bin/arangodb_operator +ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator_ops /usr/bin/arangodb_operator_ops COPY --from=builder /go/bin/dlv /usr/bin/dlv diff --git a/Makefile b/Makefile index 9500a2d2c..53bf16135 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,11 @@ BIN := $(BINDIR)/$(BINNAME) VBIN_LINUX_AMD64 := $(BINDIR)/$(RELEASE_MODE)/linux/amd64/$(BINNAME) VBIN_LINUX_ARM64 := $(BINDIR)/$(RELEASE_MODE)/linux/arm64/$(BINNAME) +BIN_OPS_NAME := $(PROJECT)_ops +BIN_OPS := $(BINDIR)/$(BIN_OPS_NAME) +VBIN_OPS_LINUX_AMD64 := $(BINDIR)/$(RELEASE_MODE)/linux/amd64/$(BIN_OPS_NAME) +VBIN_OPS_LINUX_ARM64 := $(BINDIR)/$(RELEASE_MODE)/linux/arm64/$(BIN_OPS_NAME) + ifdef VERBOSE TESTVERBOSEOPTIONS := -v endif @@ -218,7 +223,7 @@ endif .PHONY: clean clean: - rm -Rf $(BIN) $(BINDIR) $(DASHBOARDDIR)/build $(DASHBOARDDIR)/node_modules $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64) + rm -Rf $(BIN) $(BINDIR) $(DASHBOARDDIR)/build $(DASHBOARDDIR)/node_modules $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64) $(VBIN_OPS_LINUX_AMD64) $(VBIN_OPS_LINUX_ARM64) .PHONY: check-vars check-vars: @@ -276,14 +281,17 @@ bin-all: $(BIN) $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64) $(VBIN_LINUX_AMD64): $(SOURCES) dashboard/assets.go VERSION @mkdir -p $(BINDIR)/$(RELEASE_MODE)/linux/amd64 - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${GOBUILDARGS} --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_AMD64) ./ + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${GOBUILDARGS} --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_AMD64) ./cmd/main + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${GOBUILDARGS} --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_OPS_LINUX_AMD64) ./cmd/main-ops $(VBIN_LINUX_ARM64): $(SOURCES) dashboard/assets.go VERSION @mkdir -p $(BINDIR)/$(RELEASE_MODE)/linux/arm64 - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${GOBUILDARGS} --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_ARM64) ./ + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${GOBUILDARGS} --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_LINUX_ARM64) ./cmd/main + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${GOBUILDARGS} --tags "$(RELEASE_MODE)" $(COMPILE_DEBUG_FLAGS) -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(VBIN_OPS_LINUX_ARM64) ./cmd/main-ops $(BIN): $(VBIN_LINUX_AMD64) @cp "$(VBIN_LINUX_AMD64)" "$(BIN)" + @cp "$(VBIN_OPS_LINUX_AMD64)" "$(BIN_OPS)" .PHONY: docker docker: check-vars $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64) diff --git a/cmd/main.go b/cmd/cmd.go similarity index 99% rename from cmd/main.go rename to cmd/cmd.go index 73f6617cb..51e077d01 100644 --- a/cmd/main.go +++ b/cmd/cmd.go @@ -31,50 +31,39 @@ import ( "strings" "time" + deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/crd" + "github.com/arangodb/kube-arangodb/pkg/deployment/features" + "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme" + "github.com/arangodb/kube-arangodb/pkg/logging" + "github.com/arangodb/kube-arangodb/pkg/operator" + "github.com/arangodb/kube-arangodb/pkg/operator/scope" + "github.com/arangodb/kube-arangodb/pkg/server" + "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/constants" + utilsError "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" - - "github.com/gin-gonic/gin" - operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http" - + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" + "github.com/arangodb/kube-arangodb/pkg/util/probe" + "github.com/arangodb/kube-arangodb/pkg/util/retry" "github.com/arangodb/kube-arangodb/pkg/version" - "github.com/arangodb/kube-arangodb/pkg/operator/scope" - - "github.com/arangodb/kube-arangodb/pkg/deployment/features" - - "github.com/rs/zerolog/log" - - deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - - "github.com/arangodb/kube-arangodb/pkg/util" - - utilsError "github.com/arangodb/kube-arangodb/pkg/util/errors" - + "github.com/gin-gonic/gin" "github.com/pkg/errors" "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" flag "github.com/spf13/pflag" appsv1 "k8s.io/api/apps/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" v1core "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/tools/record" - - v1 "k8s.io/api/core/v1" "k8s.io/klog" - - "github.com/arangodb/kube-arangodb/pkg/crd" - "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme" - "github.com/arangodb/kube-arangodb/pkg/logging" - "github.com/arangodb/kube-arangodb/pkg/operator" - "github.com/arangodb/kube-arangodb/pkg/server" - "github.com/arangodb/kube-arangodb/pkg/util/constants" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/kclient" - "github.com/arangodb/kube-arangodb/pkg/util/probe" - "github.com/arangodb/kube-arangodb/pkg/util/retry" ) const ( diff --git a/cmd/cmd_ops.go b/cmd/cmd_ops.go new file mode 100644 index 000000000..e0ffa4ca1 --- /dev/null +++ b/cmd/cmd_ops.go @@ -0,0 +1,45 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 cmd + +import ( + goflag "flag" + + "github.com/spf13/cobra" + flag "github.com/spf13/pflag" +) + +var ( + cmdOps = cobra.Command{ + Use: "arangodb_ops", + Run: executeUsage, + } +) + +func ExecuteOps() int { + flag.CommandLine.AddGoFlagSet(goflag.CommandLine) + + if err := cmdOps.Execute(); err != nil { + return 1 + } + + return 0 +} diff --git a/cmd/main-ops/main_ops.go b/cmd/main-ops/main_ops.go new file mode 100644 index 000000000..e37a08d80 --- /dev/null +++ b/cmd/main-ops/main_ops.go @@ -0,0 +1,31 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 main + +import ( + "os" + + "github.com/arangodb/kube-arangodb/cmd" +) + +func main() { + os.Exit(cmd.ExecuteOps()) +} diff --git a/main.go b/cmd/main/main.go similarity index 100% rename from main.go rename to cmd/main/main.go diff --git a/cmd/task.go b/cmd/task.go new file mode 100644 index 000000000..28187707e --- /dev/null +++ b/cmd/task.go @@ -0,0 +1,65 @@ +// +// DISCLAIMER +// +// Copyright 2016-2022 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 cmd + +import ( + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" +) + +func init() { + var deploymentName string + + cmdMain.AddCommand(cmdTask) + cmdOps.AddCommand(cmdTask) + + cmdTask.AddCommand(cmdTaskCreate) + cmdTaskCreate.Flags().StringVarP(&deploymentName, ArgDeploymentName, "d", "", + "Name of ArangoDeployment for which Task will be created - necessary when more than one deployment exist within one namespace") + + cmdTask.AddCommand(cmdTaskState) +} + +var cmdTask = &cobra.Command{ + Use: "task", + Run: executeUsage, +} + +var cmdTaskCreate = &cobra.Command{ + Use: "create", + Short: "Create task", + Run: taskCreate, +} + +var cmdTaskState = &cobra.Command{ + Use: "state", + Short: "Get Task state", + Long: "It prints the task current state on the stdout", + Run: taskState, +} + +func taskCreate(cmd *cobra.Command, args []string) { + log.Info().Msgf("TODO: create task") +} + +func taskState(cmd *cobra.Command, args []string) { + log.Info().Msgf("TODO: check task state") +} diff --git a/pkg/apis/deployment/v1/plan.go b/pkg/apis/deployment/v1/plan.go index ef88cd16c..1d09b37b9 100644 --- a/pkg/apis/deployment/v1/plan.go +++ b/pkg/apis/deployment/v1/plan.go @@ -231,12 +231,15 @@ type Action struct { Params map[string]string `json:"params,omitempty"` // Locals additional storage for local variables which are produced during the action. Locals PlanLocals `json:"locals,omitempty"` + // ID reference of the task involved in this action (if any) + TaskID types.UID `json:"taskID,omitempty"` } // Equal compares two Actions func (a Action) Equal(other Action) bool { return a.ID == other.ID && a.Type == other.Type && + a.SetID == other.SetID && a.MemberID == other.MemberID && a.Group == other.Group && util.TimeCompareEqual(a.CreationTime, other.CreationTime) && @@ -244,7 +247,8 @@ func (a Action) Equal(other Action) bool { a.Reason == other.Reason && a.Image == other.Image && equality.Semantic.DeepEqual(a.Params, other.Params) && - a.Locals.Equal(other.Locals) + a.Locals.Equal(other.Locals) && + a.TaskID == other.TaskID } // AddParam returns copy of action with set parameter diff --git a/pkg/apis/deployment/v2alpha1/plan.go b/pkg/apis/deployment/v2alpha1/plan.go index e755ad663..527bd8aac 100644 --- a/pkg/apis/deployment/v2alpha1/plan.go +++ b/pkg/apis/deployment/v2alpha1/plan.go @@ -231,12 +231,15 @@ type Action struct { Params map[string]string `json:"params,omitempty"` // Locals additional storage for local variables which are produced during the action. Locals PlanLocals `json:"locals,omitempty"` + // ID reference of the task involved in this action (if any) + TaskID types.UID `json:"taskID,omitempty"` } // Equal compares two Actions func (a Action) Equal(other Action) bool { return a.ID == other.ID && a.Type == other.Type && + a.SetID == other.SetID && a.MemberID == other.MemberID && a.Group == other.Group && util.TimeCompareEqual(a.CreationTime, other.CreationTime) && @@ -244,7 +247,8 @@ func (a Action) Equal(other Action) bool { a.Reason == other.Reason && a.Image == other.Image && equality.Semantic.DeepEqual(a.Params, other.Params) && - a.Locals.Equal(other.Locals) + a.Locals.Equal(other.Locals) && + a.TaskID == other.TaskID } // AddParam returns copy of action with set parameter