Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow committed Nov 28, 2023
1 parent 9ed84f9 commit 791c759
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 108 deletions.
4 changes: 3 additions & 1 deletion pkg/apis/ml/v1alpha1/extension_status_metadata_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

package v1alpha1

import shared "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"

type ArangoMLExtensionStatusMetadataService struct {
// Local define the Local ArangoDeployment Metadata Service configuration
Local *ArangoMLExtensionStatusMetadataServiceLocal `json:"local,omitempty"`

// Secret define the Secret specification to store all the details
Secret *Object `json:"secret,omitempty"`
Secret *shared.Object `json:"secret,omitempty"`
}

type ArangoMLExtensionStatusMetadataServiceLocal struct {
Expand Down
79 changes: 0 additions & 79 deletions pkg/apis/ml/v1alpha1/object.go

This file was deleted.

29 changes: 1 addition & 28 deletions pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/apis/shared/v1/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package v1

import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/arangodb/kube-arangodb/pkg/apis/shared"
)
Expand All @@ -32,6 +33,9 @@ type Object struct {

// Namespace of the object. Should default to the namespace of the parent object
Namespace *string `json:"namespace,omitempty"`

// UID keeps the information about object UID
UID *types.UID `json:"uid,omitempty"`
}

func (o *Object) IsEmpty() bool {
Expand All @@ -57,6 +61,16 @@ func (o *Object) GetNamespace(obj meta.Object) string {
return obj.GetNamespace()
}

func (o *Object) GetUID() types.UID {
if o != nil {
if n := o.UID; n != nil {
return *n
}
}

return ""
}

func (o *Object) Validate() error {
if o == nil {
o = &Object{}
Expand All @@ -67,6 +81,9 @@ func (o *Object) Validate() error {
if o.Namespace != nil {
errs = append(errs, shared.PrefixResourceErrors("namespace", AsKubernetesResourceName(o.Namespace).Validate()))
}
if u := o.UID; u != nil {
errs = append(errs, shared.PrefixResourceErrors("uid", shared.ValidateUID(*u)))
}

return shared.WithErrors(errs...)
}
9 changes: 9 additions & 0 deletions pkg/apis/shared/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/apis/shared/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ package shared
import (
"regexp"

"k8s.io/apimachinery/pkg/types"

"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/strings"
)

var (
Expand Down Expand Up @@ -54,3 +57,19 @@ func ValidateOptionalResourceName(name string) error {
}
return nil
}

// ValidateUID validates if it is valid Kubernetes UID
func ValidateUID(uid types.UID) error {
v := strings.Split(string(uid), "-")

if len(v) != 0 &&
len(v[0]) != 6 &&
len(v[1]) != 4 &&
len(v[2]) != 4 &&
len(v[3]) != 4 &&
len(v[4]) != 6 {
return errors.Newf("Invalid UID: %s", uid)
}

return nil
}
33 changes: 33 additions & 0 deletions pkg/apis/shared/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// DISCLAIMER
//
// 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 shared

import (
"testing"

"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/uuid"
)

func Test_ValidateUID(t *testing.T) {
require.Error(t, ValidateUID(""))
require.NoError(t, ValidateUID(uuid.NewUUID()))
}

0 comments on commit 791c759

Please sign in to comment.