1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Action Config options (#1380)

This commit is contained in:
Adam Janikowski 2023-08-15 21:22:15 +03:00 committed by GitHub
parent 4a7d2e8f97
commit 1baa651995
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 115 additions and 0 deletions

View file

@ -51,6 +51,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/crd"
"github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache"
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile"
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme"
"github.com/arangodb/kube-arangodb/pkg/logging"
"github.com/arangodb/kube-arangodb/pkg/metrics/collector"
@ -236,6 +237,9 @@ func init() {
if err := cache.Init(&cmdMain); err != nil {
panic(err.Error())
}
if err := reconcile.ActionsConfigGlobal.Init(&cmdMain); err != nil {
panic(err.Error())
}
}
func Execute() int {

View file

@ -0,0 +1,41 @@
{{- $root := . -}}
//
// Copyright 2023 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 reconcile
import "github.com/spf13/cobra"
var ActionsConfigGlobal ActionsConfig
type ActionsConfig struct {
{{- range .configurable }}
// {{ . }} keeps configuration for action api.ActionType{{ . }}
{{ . }} Action{{ . }}Config
{{- end }}
}
// Init initializes all registered actions config options.
func (a *ActionsConfig) Init(cmd *cobra.Command) error {
{{- range .configurable }}
if err := a.{{ . }}.Init(cmd, "action.{{ . }}"); err != nil {
return err
}
{{- end }}
return nil
}

View file

@ -46,6 +46,9 @@ var actionsGoTemplate []byte
//go:embed actions.register.go.tmpl
var actionsRegisterGoTemplate []byte
//go:embed actions.config.go.tmpl
var actionsConfigGoTemplate []byte
//go:embed actions.register.test.go.tmpl
var actionsRegisterTestGoTemplate []byte
@ -175,6 +178,16 @@ func (i ActionsInput) Timeouts() map[string]string {
return r
}
func (i ActionsInput) Configurable() []string {
var r []string
for k, a := range i.Actions {
if a.Configurable {
r = append(r, k)
}
}
return r
}
type Action struct {
Timeout *meta.Duration `json:"timeout,omitempty"`
StartupFailureGracePeriod *meta.Duration `json:"startupFailureGracePeriod,omitempty"`
@ -188,6 +201,8 @@ type Action struct {
IsInternal bool `json:"isInternal"`
Optional bool `json:"optional"`
Configurable bool `json:"configurable"`
}
func (a Action) InScope(scope string) bool {
@ -267,6 +282,30 @@ func RenderActions(root string) error {
}
}
{
actions := path.Join(root, "pkg", "deployment", "reconcile", "action.config.generated.go")
out, err := os.OpenFile(actions, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return err
}
i, err := template.New("actions").Parse(string(actionsConfigGoTemplate))
if err != nil {
return err
}
if err := i.Execute(out, map[string]interface{}{
"configurable": in.Configurable(),
}); err != nil {
return err
}
if err := out.Close(); err != nil {
return err
}
}
{
actions := path.Join(root, "pkg", "deployment", "reconcile", "action.register.generated_test.go")

View file

@ -0,0 +1,31 @@
//
// Copyright 2023 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 reconcile
import "github.com/spf13/cobra"
var ActionsConfigGlobal ActionsConfig
type ActionsConfig struct {
}
// Init initializes all registered actions config options.
func (a *ActionsConfig) Init(cmd *cobra.Command) error {
return nil
}