Skip to content

Commit

Permalink
Feature] Fix CRD Schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow committed Jun 17, 2024
1 parent 34228e9 commit 4735ffe
Show file tree
Hide file tree
Showing 34 changed files with 1,409 additions and 4,112 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries
- (Feature) Fix CRD Schema types

## [1.2.41](https://github.com/arangodb/kube-arangodb/tree/1.2.41) (2024-05-24)
- (Maintenance) Bump Prometheus API Version
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ Flags:
--backup-concurrent-uploads int Number of concurrent uploads per deployment (default 4)
--chaos.allowed Set to allow chaos in deployments. Only activated when allowed and enabled in deployment
--crd.install Install missing CRD if access is possible (default true)
--crd.validation-schema stringArray Overrides default set of CRDs which should have validation schema enabled <crd-name>=<true/false>.
--crd.preserve-unknown-fields stringArray Controls which CRD should have enabled preserve unknown fields in validation schema <crd-name>=<true/false>. To apply for all, use crd-name 'all'.
--crd.validation-schema stringArray Overrides default set of CRDs which should have validation schema enabled <crd-name>=<true/false>. To apply for all, use crd-name 'all'.
--deployment.feature.agency-poll Enable Agency Poll for Enterprise deployments - Required ArangoDB 3.8.0 or higher (default true)
--deployment.feature.all Enable ALL Features
--deployment.feature.async-backup-creation Create backups asynchronously to avoid blocking the operator and reaching the timeout - Required ArangoDB 3.8.0 or higher (default true)
Expand Down
10 changes: 6 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ var (
timeout time.Duration
}
crdOptions struct {
install bool
validationSchema []string
install bool
preserveUnknownFields []string
validationSchema []string
}
operatorKubernetesOptions struct {
maxBatchSize int64
Expand Down Expand Up @@ -242,7 +243,8 @@ func init() {
f.Float32Var(&operatorKubernetesOptions.qps, "kubernetes.qps", kclient.DefaultQPS, "Number of queries per second for k8s API")
f.IntVar(&operatorKubernetesOptions.burst, "kubernetes.burst", kclient.DefaultBurst, "Burst for the k8s API")
f.BoolVar(&crdOptions.install, "crd.install", true, "Install missing CRD if access is possible")
f.StringArrayVar(&crdOptions.validationSchema, "crd.validation-schema", defaultValidationSchemaEnabled, "Overrides default set of CRDs which should have validation schema enabled <crd-name>=<true/false>.")
f.StringArrayVar(&crdOptions.preserveUnknownFields, "crd.preserve-unknown-fields", nil, "Controls which CRD should have enabled preserve unknown fields in validation schema <crd-name>=<true/false>. To apply for all, use crd-name 'all'.")
f.StringArrayVar(&crdOptions.validationSchema, "crd.validation-schema", defaultValidationSchemaEnabled, "Overrides default set of CRDs which should have validation schema enabled <crd-name>=<true/false>. To apply for all, use crd-name 'all'.")
f.IntVar(&operatorBackup.concurrentUploads, "backup-concurrent-uploads", globals.DefaultBackupConcurrentUploads, "Number of concurrent uploads per deployment")
f.Uint64Var(&memoryLimit.hardLimit, "memory-limit", 0, "Define memory limit for hard shutdown and the dump of goroutines. Used for testing")
f.StringArrayVar(&metricsOptions.excludedMetricPrefixes, "metrics.excluded-prefixes", nil, "List of the excluded metrics prefixes")
Expand Down Expand Up @@ -389,7 +391,7 @@ func executeMain(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(shutdown.Context(), time.Minute)
defer cancel()

crdOpts, err := prepareCRDOptions(crdOptions.validationSchema)
crdOpts, err := prepareCRDOptions(crdOptions.validationSchema, crdOptions.preserveUnknownFields)
if err != nil {
logger.Fatal("Invalid --crd.validation-schema args: %s", err)
}
Expand Down
119 changes: 105 additions & 14 deletions cmd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/shutdown"
)

const (
AllSchemasValue = "all"
)

var (
cmdCRD = &cobra.Command{
Use: "crd",
Expand All @@ -48,12 +52,18 @@ var (
Run: cmdCRDInstallRun,
Short: "Install and update all required CRDs",
}
cmdCRDGenerate = &cobra.Command{
Use: "generate",
Run: cmdCRDGenerateRun,
Short: "Generates YAML of all required CRDs",
}
)

var (
crdInstallOptions struct {
validationSchema []string
force bool
validationSchema []string
preserveUnknownFields []string
force bool
}
)

Expand All @@ -65,39 +75,107 @@ func init() {
cmdMain.AddCommand(cmdCRD)
cmdOps.AddCommand(cmdCRD)

f := cmdCRDInstall.Flags()
f := cmdCRD.PersistentFlags()
f.StringArrayVar(&crdInstallOptions.validationSchema, "crd.validation-schema", defaultValidationSchemaEnabled, "Controls which CRD should have validation schema <crd-name>=<true/false>.")
f.StringArrayVar(&crdInstallOptions.preserveUnknownFields, "crd.preserve-unknown-fields", nil, "Controls which CRD should have enabled preserve unknown fields in validation schema <crd-name>=<true/false>.")
f.BoolVar(&crdInstallOptions.force, "crd.force-update", false, "Enforce CRD Schema update")

cmdCRD.AddCommand(cmdCRDInstall)
cmdCRD.AddCommand(cmdCRDGenerate)
}

func prepareCRDOptions(schemaEnabledArgs []string) (map[string]crds.CRDOptions, error) {
func prepareCRDOptions(schemaEnabledArgs []string, preserveUnknownFieldsArgs []string) (map[string]crds.CRDOptions, error) {
defaultOptions := crd.GetDefaultCRDOptions()
result := make(map[string]crds.CRDOptions)
var err error

schemaEnabled := map[string]bool{}
preserveUnknownFields := map[string]bool{}

for _, arg := range schemaEnabledArgs {
parts := strings.Split(arg, "=")
parts := strings.SplitN(arg, "=", 2)

var enabled bool

if len(parts) == 2 {
enabled, err = strconv.ParseBool(parts[1])
if err != nil {
return nil, errors.Wrapf(err, "not a bool value: %s", parts[1])
}

crdName := parts[0]
opts, ok := defaultOptions[crdName]
if !ok {
return nil, fmt.Errorf("unknown CRD %s", crdName)
}

schemaEnabled[parts[0]] = enabled
}

for _, arg := range preserveUnknownFieldsArgs {
parts := strings.SplitN(arg, "=", 2)

var enabled bool

if len(parts) == 2 {
opts.WithSchema, err = strconv.ParseBool(parts[1])
enabled, err = strconv.ParseBool(parts[1])
if err != nil {
return nil, errors.Wrapf(err, "not a bool value: %s", parts[1])
}

}

preserveUnknownFields[parts[0]] = enabled
}

for k := range schemaEnabled {
if k == AllSchemasValue {
continue
}
if _, ok := defaultOptions[k]; !ok {
return nil, fmt.Errorf("unknown CRD %s", k)
}
}

for k := range preserveUnknownFields {
if k == AllSchemasValue {
continue
}
if _, ok := defaultOptions[k]; !ok {
return nil, fmt.Errorf("unknown CRD %s", k)
}
}

result[crdName] = opts
// Override the defaults
if v, ok := schemaEnabled[AllSchemasValue]; ok {
delete(preserveUnknownFields, AllSchemasValue)
for k := range defaultOptions {
z := defaultOptions[k]
z.WithSchema = v
defaultOptions[k] = z
}
}
if v, ok := preserveUnknownFields[AllSchemasValue]; ok {
delete(preserveUnknownFields, AllSchemasValue)
for k := range defaultOptions {
z := defaultOptions[k]
z.WithPreserve = v
defaultOptions[k] = z
}
}

// Set explicit words
for k, v := range schemaEnabled {
z := defaultOptions[k]
z.WithSchema = v
defaultOptions[k] = z
}
for k, v := range preserveUnknownFields {
z := defaultOptions[k]
z.WithPreserve = v
defaultOptions[k] = z
}
return result, nil

return defaultOptions, nil
}

func cmdCRDInstallRun(cmd *cobra.Command, args []string) {
crdOpts, err := prepareCRDOptions(crdInstallOptions.validationSchema)
crdOpts, err := prepareCRDOptions(crdInstallOptions.validationSchema, crdInstallOptions.preserveUnknownFields)
if err != nil {
logger.Fatal("Invalid --crd.validation-schema args: %s", err)
return
Expand All @@ -117,3 +195,16 @@ func cmdCRDInstallRun(cmd *cobra.Command, args []string) {
os.Exit(1)
}
}

func cmdCRDGenerateRun(cmd *cobra.Command, args []string) {
crdOpts, err := prepareCRDOptions(crdInstallOptions.validationSchema, crdInstallOptions.preserveUnknownFields)
if err != nil {
logger.Fatal("Invalid --crd.validation-schema args: %s", err)
return
}

err = crd.GenerateCRDYAMLWithOptions(crd.EnsureCRDOptions{IgnoreErrors: false, CRDOptions: crdOpts, ForceUpdate: crdInstallOptions.force}, cmd.OutOrStdout())
if err != nil {
os.Exit(1)
}
}
8 changes: 4 additions & 4 deletions docs/api/ArangoMember.V1.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ title: ArangoMember V1

### .spec.deletion_priority

Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L47)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L48)</sup>

DeletionPriority define Deletion Priority.
Higher value means higher priority. Default is 0.
Expand All @@ -20,23 +20,23 @@ Example: set 1 for Coordinator which should be deleted first and scale down coor

### .spec.deploymentUID

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L36)</sup>
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L37)</sup>

DeploymentUID define Deployment UID.

***

### .spec.group

Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L31)</sup>
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L32)</sup>

Group define Member Groups.

***

### .spec.id

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L33)</sup>
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.41/pkg/apis/deployment/v1/arango_member_spec.go#L34)</sup>

***

Expand Down
Loading

0 comments on commit 4735ffe

Please sign in to comment.