Skip to content

Commit

Permalink
[Feature] [ML] Add TLS Secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow committed May 1, 2024
1 parent 51989bc commit d210430
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- (Bugfix) Fix Schema Apply Checksum
- (Bugfix) Use MD5 instead of SHA256 for CRD Checksums
- (Feature) (ML) Unify API
- (Feature) (ML) Add TLS Secrets

## [1.2.40](https://github.com/arangodb/kube-arangodb/tree/1.2.40) (2024-04-10)
- (Feature) Add Core fields to the Scheduler Container Spec
Expand Down
84 changes: 82 additions & 2 deletions docs/api/ArangoMLExtension.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Links:

### .spec.deployment.gpu

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_spec_deployment.go#L52)</sup>
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_spec_deployment.go#L55)</sup>

GPU defined if GPU Jobs are enabled.

Expand Down Expand Up @@ -231,7 +231,7 @@ Links:

### .spec.deployment.port

Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_spec_deployment.go#L55)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_spec_deployment.go#L58)</sup>

Port defines on which port the container will be listening for connections

Expand Down Expand Up @@ -359,6 +359,22 @@ Links:

***

### .spec.deployment.tls.altNames

Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_spec_deployment_tls.go#L28)</sup>

AltNames define TLS AltNames used when TLS on the ArangoDB is enabled

***

### .spec.deployment.tls.enabled

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_spec_deployment_tls.go#L25)</sup>

Enabled define if TLS Should be enabled. If is not set then default is taken from ArangoDeployment settings

***

### .spec.deployment.tolerations

Type: `[]core.Toleration` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/scheduler/v1alpha1/pod/resources/scheduling.go#L49)</sup>
Expand Down Expand Up @@ -2873,6 +2889,38 @@ UID keeps the information about object UID

## Status

### .status.arangoDB.jwtTokenSecret.checksum

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L61)</sup>

UID keeps the information about object Checksum

***

### .status.arangoDB.jwtTokenSecret.name

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L52)</sup>

Name of the object

***

### .status.arangoDB.jwtTokenSecret.namespace

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L55)</sup>

Namespace of the object. Should default to the namespace of the parent object

***

### .status.arangoDB.jwtTokenSecret.uid

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L58)</sup>

UID keeps the information about object UID

***

### .status.arangoDB.secret.checksum

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L61)</sup>
Expand Down Expand Up @@ -2905,6 +2953,38 @@ UID keeps the information about object UID

***

### .status.arangoDB.tls.checksum

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L61)</sup>

UID keeps the information about object Checksum

***

### .status.arangoDB.tls.name

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L52)</sup>

Name of the object

***

### .status.arangoDB.tls.namespace

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L55)</sup>

Namespace of the object. Should default to the namespace of the parent object

***

### .status.arangoDB.tls.uid

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/shared/v1/object.go#L58)</sup>

UID keeps the information about object UID

***

### .status.conditions

Type: `api.Conditions` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.40/pkg/apis/ml/v1alpha1/extension_status.go#L31)</sup>
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_spec_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type ArangoMLExtensionSpecDeployment struct {
// Service defines how components will be exposed
Service *ArangoMLExtensionSpecDeploymentService `json:"service,omitempty"`

// TLS defined TLS Settings for extension
TLS *ArangoMLExtensionSpecDeploymentTLS `json:"tls,omitempty"`

// Pod defines base template for pods
*schedulerPodApi.Pod

Expand Down Expand Up @@ -99,6 +102,13 @@ func (s *ArangoMLExtensionSpecDeployment) GetService() *ArangoMLExtensionSpecDep
return s.Service
}

func (s *ArangoMLExtensionSpecDeployment) GetTLS() *ArangoMLExtensionSpecDeploymentTLS {
if s == nil {
return nil
}
return s.TLS
}

func (s *ArangoMLExtensionSpecDeployment) Validate() error {
if s == nil {
return nil
Expand Down
29 changes: 29 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_spec_deployment_tls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// DISCLAIMER
//
// Copyright 2024 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 v1alpha1

type ArangoMLExtensionSpecDeploymentTLS struct {
// Enabled define if TLS Should be enabled. If is not set then default is taken from ArangoDeployment settings
Enabled *bool `json:"enabled,omitempty"`

// AltNames define TLS AltNames used when TLS on the ArangoDB is enabled
AltNames []string `json:"altNames,omitempty"`
}
4 changes: 4 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_status_arangodb_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ import sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
type ArangoMLExtensionStatusArangoDBRef struct {
// Secret keeps the information about ArangoDB deployment
Secret *sharedApi.Object `json:"secret,omitempty"`
// TLS keeps information about TLS Secret rendered from ArangoDB deployment
TLS *sharedApi.Object `json:"tls,omitempty"`
// JWTTokenSecret keeps the JWT for ArangoDB authentication (only when ArangoDeployment has JWT enabled)
JWTTokenSecret *sharedApi.Object `json:"jwtTokenSecret,omitempty"`
}
41 changes: 41 additions & 0 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.

14 changes: 14 additions & 0 deletions pkg/apis/shared/v1/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ func (o *Object) GetUID() types.UID {
return ""
}

func (o *Object) AsUIDPrecondition() *meta.Preconditions {
if o == nil || o.UID == nil {
return nil
}

uid := o.GetUID()

if uid == "" {
return nil
}

return meta.NewUIDPreconditions(string(uid))
}

func (o *Object) GetChecksum() string {
if o != nil {
if n := o.Checksum; n != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/crd/crds/ml-extension.schema.generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,18 @@ v1alpha1:
format: int32
type: integer
type: object
tls:
description: TLS defined TLS Settings for extension
properties:
altNames:
description: AltNames define TLS AltNames used when TLS on the ArangoDB is enabled
items:
type: string
type: array
enabled:
description: Enabled define if TLS Should be enabled. If is not set then default is taken from ArangoDeployment settings
type: boolean
type: object
tolerations:
items:
properties:
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/resources/certificates_tls.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 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.
Expand Down Expand Up @@ -113,7 +113,8 @@ func createTLSServerCertificate(ctx context.Context, log logging.Logger, cachedS
strings.TrimSpace(priv)

err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
return k8sutil.CreateTLSKeyfileSecret(ctxChild, secrets, secretName, keyfile, ownerRef)
_, err := k8sutil.CreateTLSKeyfileSecret(ctxChild, secrets, secretName, keyfile, ownerRef)
return err
})
if err != nil {
if kerrors.IsAlreadyExists(err) {
Expand Down
35 changes: 34 additions & 1 deletion pkg/util/context.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 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.
Expand Down Expand Up @@ -64,6 +64,39 @@ func WithContextTimeoutP2A2[P1, P2, A1, A2 interface{}](ctx context.Context, tim
return f(nCtx, a1, a2)
}

func WithKubernetesContextTimeoutP1A4[P1, A1, A2, A3, A4 interface{}](ctx context.Context, f func(context.Context, A1, A2, A3, A4) P1, a1 A1, a2 A2, a3 A3, a4 A4) P1 {
return WithContextTimeoutP1A4(ctx, globals.GetGlobals().Timeouts().Kubernetes().Get(), f, a1, a2, a3, a4)
}

func WithContextTimeoutP1A4[P1, A1, A2, A3, A4 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2, A3, A4) P1, a1 A1, a2 A2, a3 A3, a4 A4) P1 {
nCtx, c := context.WithTimeout(ctx, timeout)
defer c()

return f(nCtx, a1, a2, a3, a4)
}

func WithKubernetesContextTimeoutP2A4[P1, P2, A1, A2, A3, A4 interface{}](ctx context.Context, f func(context.Context, A1, A2, A3, A4) (P1, P2), a1 A1, a2 A2, a3 A3, a4 A4) (P1, P2) {
return WithContextTimeoutP2A4(ctx, globals.GetGlobals().Timeouts().Kubernetes().Get(), f, a1, a2, a3, a4)
}

func WithContextTimeoutP2A4[P1, P2, A1, A2, A3, A4 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2, A3, A4) (P1, P2), a1 A1, a2 A2, a3 A3, a4 A4) (P1, P2) {
nCtx, c := context.WithTimeout(ctx, timeout)
defer c()

return f(nCtx, a1, a2, a3, a4)
}

func WithKubernetesContextTimeoutP4A3[P1, P2, P3, P4, A1, A2, A3 interface{}](ctx context.Context, f func(context.Context, A1, A2, A3) (P1, P2, P3, P4), a1 A1, a2 A2, a3 A3) (P1, P2, P3, P4) {
return WithContextTimeoutP4A3(ctx, globals.GetGlobals().Timeouts().Kubernetes().Get(), f, a1, a2, a3)
}

func WithContextTimeoutP4A3[P1, P2, P3, P4, A1, A2, A3 interface{}](ctx context.Context, timeout time.Duration, f func(context.Context, A1, A2, A3) (P1, P2, P3, P4), a1 A1, a2 A2, a3 A3) (P1, P2, P3, P4) {
nCtx, c := context.WithTimeout(ctx, timeout)
defer c()

return f(nCtx, a1, a2, a3)
}

type PatchInterface[P1 meta.Object] interface {
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (P1, error)
}
Expand Down
Loading

0 comments on commit d210430

Please sign in to comment.