Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
1 change: 1 addition & 0 deletions Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both binaries are expected to have the same build params, it is possible to slightly simplify the code using $(foreach

Example in arangosync: https://github.com/arangodb/arangosync/blob/feature/arangosync-migration/Makefile#L157

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to implement this more refactor in the project files structure is required since the paths are different (i can not place all main files under the same paths due to the linter requirements)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwierzbo I'm just worried we have another new binary is planned to be added and it would multiply the duplication even more. But I think it can be refactored in a separate PR 👍

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)
Expand Down
47 changes: 18 additions & 29 deletions cmd/main.go → cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,39 @@ import (
"strings"
"time"

"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/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/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"
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/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 (
Expand Down
45 changes: 45 additions & 0 deletions cmd/cmd_ops.go
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions cmd/main-ops/main_ops.go
Original file line number Diff line number Diff line change
@@ -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())
}
File renamed without changes.
65 changes: 65 additions & 0 deletions cmd/task.go
Original file line number Diff line number Diff line change
@@ -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")
}
6 changes: 5 additions & 1 deletion pkg/apis/deployment/v1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,24 @@ 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) &&
util.TimeCompareEqualPointer(a.StartTime, other.StartTime) &&
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
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/deployment/v2alpha1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,24 @@ 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) &&
util.TimeCompareEqualPointer(a.StartTime, other.StartTime) &&
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
Expand Down