Skip to content

Commit 168e2ba

Browse files
author
lamai93
committed
Modified Spec definition for license key.
1 parent 0dbb817 commit 168e2ba

File tree

7 files changed

+102
-42
lines changed

7 files changed

+102
-42
lines changed

pkg/apis/deployment/v1alpha/deployment_spec.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"reflect"
2727

2828
"github.com/arangodb/kube-arangodb/pkg/util"
29-
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3029
"github.com/pkg/errors"
3130
"k8s.io/api/core/v1"
3231
)
@@ -55,13 +54,13 @@ type DeploymentSpec struct {
5554
ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
5655
DowntimeAllowed *bool `json:"downtimeAllowed,omitempty"`
5756
DisableIPv6 *bool `json:"disableIPv6,omitempty"`
58-
LicenseKey *string `json:"licenseKey,omitempty"`
5957

6058
ExternalAccess ExternalAccessSpec `json:"externalAccess"`
6159
RocksDB RocksDBSpec `json:"rocksdb"`
6260
Authentication AuthenticationSpec `json:"auth"`
6361
TLS TLSSpec `json:"tls"`
6462
Sync SyncSpec `json:"sync"`
63+
License LicenseSpec `json:"license"`
6564

6665
Single ServerGroupSpec `json:"single"`
6766
Agents ServerGroupSpec `json:"agents"`
@@ -126,20 +125,6 @@ func (s DeploymentSpec) IsAuthenticated() bool {
126125
return s.Authentication.IsAuthenticated()
127126
}
128127

129-
// HasLicenseKey returns true if a license key secret name was set
130-
func (s DeploymentSpec) HasLicenseKey() bool {
131-
return s.LicenseKey != nil
132-
}
133-
134-
// GetLicenseKey returns the license key if set. Empty string otherwise.
135-
func (s DeploymentSpec) GetLicenseKey() string {
136-
if s.HasLicenseKey() {
137-
return *s.LicenseKey
138-
}
139-
140-
return ""
141-
}
142-
143128
// IsSecure returns true when SSL is enabled
144129
func (s DeploymentSpec) IsSecure() bool {
145130
return s.TLS.IsSecure()
@@ -220,9 +205,7 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
220205
if s.DisableIPv6 == nil {
221206
s.DisableIPv6 = util.NewBoolOrNil(source.DisableIPv6)
222207
}
223-
if s.LicenseKey == nil {
224-
s.LicenseKey = util.NewStringOrNil(source.LicenseKey)
225-
}
208+
s.License.SetDefaultsFrom(source.License)
226209
s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess)
227210
s.RocksDB.SetDefaultsFrom(source.RocksDB)
228211
s.Authentication.SetDefaultsFrom(source.Authentication)
@@ -291,10 +274,8 @@ func (s *DeploymentSpec) Validate() error {
291274
if err := s.Chaos.Validate(); err != nil {
292275
return maskAny(errors.Wrap(err, "spec.chaos"))
293276
}
294-
if s.HasLicenseKey() {
295-
if err := k8sutil.ValidateResourceName(s.GetLicenseKey()); err != nil {
296-
return maskAny(errors.Wrap(err, "spec.licenseKey"))
297-
}
277+
if err := s.License.Validate(); err != nil {
278+
return maskAny(errors.Wrap(err, "spec.licenseKey"))
298279
}
299280
return nil
300281
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 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 v1alpha
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/util"
25+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
26+
)
27+
28+
// LicenseSpec holds the license related information
29+
type LicenseSpec struct {
30+
SecretName *string `json:"secretName,omitempty"`
31+
}
32+
33+
// HasSecretName returns true if a license key secret name was set
34+
func (s LicenseSpec) HasSecretName() bool {
35+
return s.SecretName != nil
36+
}
37+
38+
// GetSecretName returns the license key if set. Empty string otherwise.
39+
func (s LicenseSpec) GetSecretName() string {
40+
if s.HasSecretName() {
41+
return *s.SecretName
42+
}
43+
44+
return ""
45+
}
46+
47+
// Validate validates the LicenseSpec
48+
func (s LicenseSpec) Validate() error {
49+
if s.HasSecretName() {
50+
if err := k8sutil.ValidateResourceName(s.GetSecretName()); err != nil {
51+
return err
52+
}
53+
}
54+
55+
return nil
56+
}
57+
58+
// SetDefaultsFrom fills all values not set in s with values from other
59+
func (s LicenseSpec) SetDefaultsFrom(other LicenseSpec) {
60+
if !s.HasSecretName() {
61+
s.SecretName = util.NewStringOrNil(other.SecretName)
62+
}
63+
}

pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/images.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
114114
// Pod found
115115
if k8sutil.IsPodFailed(pod) {
116116
// Wait some time before deleting the pod
117-
log.Debug().Msgf("now: %v, then: %v", time.Now(), pod.GetCreationTimestamp())
118117
if time.Now().After(pod.GetCreationTimestamp().Add(30 * time.Second)) {
119118
if err := ib.KubeCli.CoreV1().Pods(ns).Delete(podName, nil); err != nil && !k8sutil.IsNotFound(err) {
120119
log.Warn().Err(err).Msg("Failed to delete Image ID Pod")
@@ -192,9 +191,9 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
192191
serviceAccountName := ""
193192

194193
env := make(map[string]k8sutil.EnvValue)
195-
if ib.Spec.HasLicenseKey() {
194+
if ib.Spec.License.HasSecretName() {
196195
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
197-
SecretName: ib.Spec.GetLicenseKey(),
196+
SecretName: ib.Spec.License.GetSecretName(),
198197
SecretKey: constants.SecretKeyToken,
199198
}
200199
}

pkg/deployment/resources/license.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929

3030
// ValidateLicenseKeySecret checks if the licens key secret exists and is valid
3131
func (r *Resources) ValidateLicenseKeySecret() error {
32-
spec := r.context.GetSpec()
32+
spec := r.context.GetSpec().License
3333

34-
if spec.HasLicenseKey() {
35-
secretName := spec.GetLicenseKey()
34+
if spec.HasSecretName() {
35+
secretName := spec.GetSecretName()
3636

3737
kubecli := r.context.GetKubeCli()
3838
ns := r.context.GetNamespace()

pkg/deployment/resources/pod_creator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,9 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
526526
}
527527
}
528528

529-
if spec.HasLicenseKey() {
529+
if spec.License.HasSecretName() {
530530
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
531-
SecretName: spec.GetLicenseKey(),
531+
SecretName: spec.License.GetSecretName(),
532532
SecretKey: constants.SecretKeyToken,
533533
}
534534
}
@@ -599,9 +599,9 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
599599
SecretKey: constants.SecretKeyToken,
600600
}
601601
}
602-
if spec.HasLicenseKey() {
602+
if spec.License.HasSecretName() {
603603
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
604-
SecretName: spec.GetLicenseKey(),
604+
SecretName: spec.License.GetSecretName(),
605605
SecretKey: constants.SecretKeyToken,
606606
}
607607
}

scripts/kube_create_license_key_secret.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/sh
22

3-
if [ -z $2 ]; then
3+
LICENSE=$2
4+
NS=$1
5+
6+
if [ -z $LICENSE ]; then
47
echo "No enterprise license set"
58
exit 0
69
fi
710

8-
LICENSE=$(echo "${2}" | base64 -w 0 )
9-
NS=$1
10-
1111
if [ -z $NS ]; then
1212
echo "Specify a namespace argument"
1313
exit 1

0 commit comments

Comments
 (0)