Skip to content

Commit ccf6f11

Browse files
authored
[Feature] OPS CLI with Arango Task (#1003)
1 parent d8072ee commit ccf6f11

File tree

11 files changed

+183
-34
lines changed

11 files changed

+183
-34
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- (Feature) Add RestartPolicyAlways to ArangoDeployment in order to restart ArangoDB on failure
1212
- (Feature) Set a leader in active fail-over mode
1313
- (Feature) Use policy/v1 instead policy/v1beta1
14+
- (Feature) OPS CLI with Arango Task
1415

1516
## [1.2.13](https://github.com/arangodb/kube-arangodb/tree/1.2.13) (2022-06-07)
1617
- (Bugfix) Fix arangosync members state inspection

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ ADD ./LICENSE /licenses/LICENSE
1515
ARG RELEASE_MODE=community
1616
ARG TARGETARCH
1717
ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator /usr/bin/arangodb_operator
18+
ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator_ops /usr/bin/arangodb_operator_ops
1819

1920
ENTRYPOINT [ "/usr/bin/arangodb_operator" ]

Dockerfile.debug

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUN apk add --no-cache libc6-compat
2525

2626
ADD ./LICENSE /licenses/LICENSE
2727
ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator /usr/bin/arangodb_operator
28+
ADD bin/${RELEASE_MODE}/linux/${TARGETARCH}/arangodb_operator_ops /usr/bin/arangodb_operator_ops
2829

2930
COPY --from=builder /go/bin/dlv /usr/bin/dlv
3031

Makefile

+11-3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ BIN := $(BINDIR)/$(BINNAME)
146146
VBIN_LINUX_AMD64 := $(BINDIR)/$(RELEASE_MODE)/linux/amd64/$(BINNAME)
147147
VBIN_LINUX_ARM64 := $(BINDIR)/$(RELEASE_MODE)/linux/arm64/$(BINNAME)
148148

149+
BIN_OPS_NAME := $(PROJECT)_ops
150+
BIN_OPS := $(BINDIR)/$(BIN_OPS_NAME)
151+
VBIN_OPS_LINUX_AMD64 := $(BINDIR)/$(RELEASE_MODE)/linux/amd64/$(BIN_OPS_NAME)
152+
VBIN_OPS_LINUX_ARM64 := $(BINDIR)/$(RELEASE_MODE)/linux/arm64/$(BIN_OPS_NAME)
153+
149154
ifdef VERBOSE
150155
TESTVERBOSEOPTIONS := -v
151156
endif
@@ -218,7 +223,7 @@ endif
218223

219224
.PHONY: clean
220225
clean:
221-
rm -Rf $(BIN) $(BINDIR) $(DASHBOARDDIR)/build $(DASHBOARDDIR)/node_modules $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64)
226+
rm -Rf $(BIN) $(BINDIR) $(DASHBOARDDIR)/build $(DASHBOARDDIR)/node_modules $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64) $(VBIN_OPS_LINUX_AMD64) $(VBIN_OPS_LINUX_ARM64)
222227

223228
.PHONY: check-vars
224229
check-vars:
@@ -276,14 +281,17 @@ bin-all: $(BIN) $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64)
276281

277282
$(VBIN_LINUX_AMD64): $(SOURCES) dashboard/assets.go VERSION
278283
@mkdir -p $(BINDIR)/$(RELEASE_MODE)/linux/amd64
279-
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) ./
284+
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
285+
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
280286

281287
$(VBIN_LINUX_ARM64): $(SOURCES) dashboard/assets.go VERSION
282288
@mkdir -p $(BINDIR)/$(RELEASE_MODE)/linux/arm64
283-
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) ./
289+
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
290+
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
284291

285292
$(BIN): $(VBIN_LINUX_AMD64)
286293
@cp "$(VBIN_LINUX_AMD64)" "$(BIN)"
294+
@cp "$(VBIN_OPS_LINUX_AMD64)" "$(BIN_OPS)"
287295

288296
.PHONY: docker
289297
docker: check-vars $(VBIN_LINUX_AMD64) $(VBIN_LINUX_ARM64)

cmd/main.go cmd/cmd.go

+18-29
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,39 @@ import (
3131
"strings"
3232
"time"
3333

34-
"github.com/arangodb/kube-arangodb/pkg/util/globals"
35-
36-
"github.com/gin-gonic/gin"
37-
38-
operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
39-
40-
"github.com/arangodb/kube-arangodb/pkg/version"
41-
42-
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
43-
44-
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
45-
46-
"github.com/rs/zerolog/log"
47-
4834
deploymentApi "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
49-
35+
"github.com/arangodb/kube-arangodb/pkg/crd"
36+
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
37+
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme"
38+
"github.com/arangodb/kube-arangodb/pkg/logging"
39+
"github.com/arangodb/kube-arangodb/pkg/operator"
40+
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
41+
"github.com/arangodb/kube-arangodb/pkg/server"
5042
"github.com/arangodb/kube-arangodb/pkg/util"
51-
43+
"github.com/arangodb/kube-arangodb/pkg/util/constants"
5244
utilsError "github.com/arangodb/kube-arangodb/pkg/util/errors"
45+
"github.com/arangodb/kube-arangodb/pkg/util/globals"
46+
operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
47+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
48+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
49+
"github.com/arangodb/kube-arangodb/pkg/util/probe"
50+
"github.com/arangodb/kube-arangodb/pkg/util/retry"
51+
"github.com/arangodb/kube-arangodb/pkg/version"
5352

53+
"github.com/gin-gonic/gin"
5454
"github.com/pkg/errors"
5555
"github.com/rs/zerolog"
56+
"github.com/rs/zerolog/log"
5657
"github.com/spf13/cobra"
5758
flag "github.com/spf13/pflag"
5859
appsv1 "k8s.io/api/apps/v1"
60+
v1 "k8s.io/api/core/v1"
5961
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6062
"k8s.io/apimachinery/pkg/runtime"
6163
"k8s.io/client-go/kubernetes"
6264
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
6365
"k8s.io/client-go/tools/record"
64-
65-
v1 "k8s.io/api/core/v1"
6666
"k8s.io/klog"
67-
68-
"github.com/arangodb/kube-arangodb/pkg/crd"
69-
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme"
70-
"github.com/arangodb/kube-arangodb/pkg/logging"
71-
"github.com/arangodb/kube-arangodb/pkg/operator"
72-
"github.com/arangodb/kube-arangodb/pkg/server"
73-
"github.com/arangodb/kube-arangodb/pkg/util/constants"
74-
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
75-
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
76-
"github.com/arangodb/kube-arangodb/pkg/util/probe"
77-
"github.com/arangodb/kube-arangodb/pkg/util/retry"
7867
)
7968

8069
const (

cmd/cmd_ops.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package cmd
22+
23+
import (
24+
goflag "flag"
25+
26+
"github.com/spf13/cobra"
27+
flag "github.com/spf13/pflag"
28+
)
29+
30+
var (
31+
cmdOps = cobra.Command{
32+
Use: "arangodb_ops",
33+
Run: executeUsage,
34+
}
35+
)
36+
37+
func ExecuteOps() int {
38+
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
39+
40+
if err := cmdOps.Execute(); err != nil {
41+
return 1
42+
}
43+
44+
return 0
45+
}

cmd/main-ops/main_ops.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package main
22+
23+
import (
24+
"os"
25+
26+
"github.com/arangodb/kube-arangodb/cmd"
27+
)
28+
29+
func main() {
30+
os.Exit(cmd.ExecuteOps())
31+
}

main.go cmd/main/main.go

File renamed without changes.

cmd/task.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package cmd
22+
23+
import (
24+
"github.com/rs/zerolog/log"
25+
"github.com/spf13/cobra"
26+
)
27+
28+
func init() {
29+
var deploymentName string
30+
31+
cmdMain.AddCommand(cmdTask)
32+
cmdOps.AddCommand(cmdTask)
33+
34+
cmdTask.AddCommand(cmdTaskCreate)
35+
cmdTaskCreate.Flags().StringVarP(&deploymentName, ArgDeploymentName, "d", "",
36+
"Name of ArangoDeployment for which Task will be created - necessary when more than one deployment exist within one namespace")
37+
38+
cmdTask.AddCommand(cmdTaskState)
39+
}
40+
41+
var cmdTask = &cobra.Command{
42+
Use: "task",
43+
Run: executeUsage,
44+
}
45+
46+
var cmdTaskCreate = &cobra.Command{
47+
Use: "create",
48+
Short: "Create task",
49+
Run: taskCreate,
50+
}
51+
52+
var cmdTaskState = &cobra.Command{
53+
Use: "state",
54+
Short: "Get Task state",
55+
Long: "It prints the task current state on the stdout",
56+
Run: taskState,
57+
}
58+
59+
func taskCreate(cmd *cobra.Command, args []string) {
60+
log.Info().Msgf("TODO: create task")
61+
}
62+
63+
func taskState(cmd *cobra.Command, args []string) {
64+
log.Info().Msgf("TODO: check task state")
65+
}

pkg/apis/deployment/v1/plan.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,24 @@ type Action struct {
231231
Params map[string]string `json:"params,omitempty"`
232232
// Locals additional storage for local variables which are produced during the action.
233233
Locals PlanLocals `json:"locals,omitempty"`
234+
// ID reference of the task involved in this action (if any)
235+
TaskID types.UID `json:"taskID,omitempty"`
234236
}
235237

236238
// Equal compares two Actions
237239
func (a Action) Equal(other Action) bool {
238240
return a.ID == other.ID &&
239241
a.Type == other.Type &&
242+
a.SetID == other.SetID &&
240243
a.MemberID == other.MemberID &&
241244
a.Group == other.Group &&
242245
util.TimeCompareEqual(a.CreationTime, other.CreationTime) &&
243246
util.TimeCompareEqualPointer(a.StartTime, other.StartTime) &&
244247
a.Reason == other.Reason &&
245248
a.Image == other.Image &&
246249
equality.Semantic.DeepEqual(a.Params, other.Params) &&
247-
a.Locals.Equal(other.Locals)
250+
a.Locals.Equal(other.Locals) &&
251+
a.TaskID == other.TaskID
248252
}
249253

250254
// AddParam returns copy of action with set parameter

pkg/apis/deployment/v2alpha1/plan.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,24 @@ type Action struct {
231231
Params map[string]string `json:"params,omitempty"`
232232
// Locals additional storage for local variables which are produced during the action.
233233
Locals PlanLocals `json:"locals,omitempty"`
234+
// ID reference of the task involved in this action (if any)
235+
TaskID types.UID `json:"taskID,omitempty"`
234236
}
235237

236238
// Equal compares two Actions
237239
func (a Action) Equal(other Action) bool {
238240
return a.ID == other.ID &&
239241
a.Type == other.Type &&
242+
a.SetID == other.SetID &&
240243
a.MemberID == other.MemberID &&
241244
a.Group == other.Group &&
242245
util.TimeCompareEqual(a.CreationTime, other.CreationTime) &&
243246
util.TimeCompareEqualPointer(a.StartTime, other.StartTime) &&
244247
a.Reason == other.Reason &&
245248
a.Image == other.Image &&
246249
equality.Semantic.DeepEqual(a.Params, other.Params) &&
247-
a.Locals.Equal(other.Locals)
250+
a.Locals.Equal(other.Locals) &&
251+
a.TaskID == other.TaskID
248252
}
249253

250254
// AddParam returns copy of action with set parameter

0 commit comments

Comments
 (0)