mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] OPS CLI with Arango Task (#1003)
This commit is contained in:
parent
d8072eed7b
commit
ccf6f1148b
11 changed files with 183 additions and 34 deletions
|
@ -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
|
||||
|
|
|
@ -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" ]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
14
Makefile
14
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)
|
||||
|
|
|
@ -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 (
|
45
cmd/cmd_ops.go
Normal file
45
cmd/cmd_ops.go
Normal file
|
@ -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
|
||||
}
|
31
cmd/main-ops/main_ops.go
Normal file
31
cmd/main-ops/main_ops.go
Normal file
|
@ -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())
|
||||
}
|
65
cmd/task.go
Normal file
65
cmd/task.go
Normal file
|
@ -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")
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue