mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
Modified Spec definition for license key.
This commit is contained in:
parent
0dbb8175b0
commit
168e2ba7cc
7 changed files with 102 additions and 42 deletions
|
@ -26,7 +26,6 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/arangodb/kube-arangodb/pkg/util"
|
"github.com/arangodb/kube-arangodb/pkg/util"
|
||||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
)
|
)
|
||||||
|
@ -55,13 +54,13 @@ type DeploymentSpec struct {
|
||||||
ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
|
ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
|
||||||
DowntimeAllowed *bool `json:"downtimeAllowed,omitempty"`
|
DowntimeAllowed *bool `json:"downtimeAllowed,omitempty"`
|
||||||
DisableIPv6 *bool `json:"disableIPv6,omitempty"`
|
DisableIPv6 *bool `json:"disableIPv6,omitempty"`
|
||||||
LicenseKey *string `json:"licenseKey,omitempty"`
|
|
||||||
|
|
||||||
ExternalAccess ExternalAccessSpec `json:"externalAccess"`
|
ExternalAccess ExternalAccessSpec `json:"externalAccess"`
|
||||||
RocksDB RocksDBSpec `json:"rocksdb"`
|
RocksDB RocksDBSpec `json:"rocksdb"`
|
||||||
Authentication AuthenticationSpec `json:"auth"`
|
Authentication AuthenticationSpec `json:"auth"`
|
||||||
TLS TLSSpec `json:"tls"`
|
TLS TLSSpec `json:"tls"`
|
||||||
Sync SyncSpec `json:"sync"`
|
Sync SyncSpec `json:"sync"`
|
||||||
|
License LicenseSpec `json:"license"`
|
||||||
|
|
||||||
Single ServerGroupSpec `json:"single"`
|
Single ServerGroupSpec `json:"single"`
|
||||||
Agents ServerGroupSpec `json:"agents"`
|
Agents ServerGroupSpec `json:"agents"`
|
||||||
|
@ -126,20 +125,6 @@ func (s DeploymentSpec) IsAuthenticated() bool {
|
||||||
return s.Authentication.IsAuthenticated()
|
return s.Authentication.IsAuthenticated()
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasLicenseKey returns true if a license key secret name was set
|
|
||||||
func (s DeploymentSpec) HasLicenseKey() bool {
|
|
||||||
return s.LicenseKey != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLicenseKey returns the license key if set. Empty string otherwise.
|
|
||||||
func (s DeploymentSpec) GetLicenseKey() string {
|
|
||||||
if s.HasLicenseKey() {
|
|
||||||
return *s.LicenseKey
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsSecure returns true when SSL is enabled
|
// IsSecure returns true when SSL is enabled
|
||||||
func (s DeploymentSpec) IsSecure() bool {
|
func (s DeploymentSpec) IsSecure() bool {
|
||||||
return s.TLS.IsSecure()
|
return s.TLS.IsSecure()
|
||||||
|
@ -220,9 +205,7 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
|
||||||
if s.DisableIPv6 == nil {
|
if s.DisableIPv6 == nil {
|
||||||
s.DisableIPv6 = util.NewBoolOrNil(source.DisableIPv6)
|
s.DisableIPv6 = util.NewBoolOrNil(source.DisableIPv6)
|
||||||
}
|
}
|
||||||
if s.LicenseKey == nil {
|
s.License.SetDefaultsFrom(source.License)
|
||||||
s.LicenseKey = util.NewStringOrNil(source.LicenseKey)
|
|
||||||
}
|
|
||||||
s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess)
|
s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess)
|
||||||
s.RocksDB.SetDefaultsFrom(source.RocksDB)
|
s.RocksDB.SetDefaultsFrom(source.RocksDB)
|
||||||
s.Authentication.SetDefaultsFrom(source.Authentication)
|
s.Authentication.SetDefaultsFrom(source.Authentication)
|
||||||
|
@ -291,10 +274,8 @@ func (s *DeploymentSpec) Validate() error {
|
||||||
if err := s.Chaos.Validate(); err != nil {
|
if err := s.Chaos.Validate(); err != nil {
|
||||||
return maskAny(errors.Wrap(err, "spec.chaos"))
|
return maskAny(errors.Wrap(err, "spec.chaos"))
|
||||||
}
|
}
|
||||||
if s.HasLicenseKey() {
|
if err := s.License.Validate(); err != nil {
|
||||||
if err := k8sutil.ValidateResourceName(s.GetLicenseKey()); err != nil {
|
return maskAny(errors.Wrap(err, "spec.licenseKey"))
|
||||||
return maskAny(errors.Wrap(err, "spec.licenseKey"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
63
pkg/apis/deployment/v1alpha/license_spec.go
Normal file
63
pkg/apis/deployment/v1alpha/license_spec.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
//
|
||||||
|
// DISCLAIMER
|
||||||
|
//
|
||||||
|
// Copyright 2018 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 v1alpha
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/arangodb/kube-arangodb/pkg/util"
|
||||||
|
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LicenseSpec holds the license related information
|
||||||
|
type LicenseSpec struct {
|
||||||
|
SecretName *string `json:"secretName,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasSecretName returns true if a license key secret name was set
|
||||||
|
func (s LicenseSpec) HasSecretName() bool {
|
||||||
|
return s.SecretName != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSecretName returns the license key if set. Empty string otherwise.
|
||||||
|
func (s LicenseSpec) GetSecretName() string {
|
||||||
|
if s.HasSecretName() {
|
||||||
|
return *s.SecretName
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates the LicenseSpec
|
||||||
|
func (s LicenseSpec) Validate() error {
|
||||||
|
if s.HasSecretName() {
|
||||||
|
if err := k8sutil.ValidateResourceName(s.GetSecretName()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDefaultsFrom fills all values not set in s with values from other
|
||||||
|
func (s LicenseSpec) SetDefaultsFrom(other LicenseSpec) {
|
||||||
|
if !s.HasSecretName() {
|
||||||
|
s.SecretName = util.NewStringOrNil(other.SecretName)
|
||||||
|
}
|
||||||
|
}
|
|
@ -244,16 +244,12 @@ func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
|
||||||
*out = new(bool)
|
*out = new(bool)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
if in.LicenseKey != nil {
|
|
||||||
in, out := &in.LicenseKey, &out.LicenseKey
|
|
||||||
*out = new(string)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
in.ExternalAccess.DeepCopyInto(&out.ExternalAccess)
|
in.ExternalAccess.DeepCopyInto(&out.ExternalAccess)
|
||||||
in.RocksDB.DeepCopyInto(&out.RocksDB)
|
in.RocksDB.DeepCopyInto(&out.RocksDB)
|
||||||
in.Authentication.DeepCopyInto(&out.Authentication)
|
in.Authentication.DeepCopyInto(&out.Authentication)
|
||||||
in.TLS.DeepCopyInto(&out.TLS)
|
in.TLS.DeepCopyInto(&out.TLS)
|
||||||
in.Sync.DeepCopyInto(&out.Sync)
|
in.Sync.DeepCopyInto(&out.Sync)
|
||||||
|
in.License.DeepCopyInto(&out.License)
|
||||||
in.Single.DeepCopyInto(&out.Single)
|
in.Single.DeepCopyInto(&out.Single)
|
||||||
in.Agents.DeepCopyInto(&out.Agents)
|
in.Agents.DeepCopyInto(&out.Agents)
|
||||||
in.DBServers.DeepCopyInto(&out.DBServers)
|
in.DBServers.DeepCopyInto(&out.DBServers)
|
||||||
|
@ -450,6 +446,27 @@ func (in ImageInfoList) DeepCopy() ImageInfoList {
|
||||||
return *out
|
return *out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *LicenseSpec) DeepCopyInto(out *LicenseSpec) {
|
||||||
|
*out = *in
|
||||||
|
if in.SecretName != nil {
|
||||||
|
in, out := &in.SecretName, &out.SecretName
|
||||||
|
*out = new(string)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LicenseSpec.
|
||||||
|
func (in *LicenseSpec) DeepCopy() *LicenseSpec {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(LicenseSpec)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *MemberStatus) DeepCopyInto(out *MemberStatus) {
|
func (in *MemberStatus) DeepCopyInto(out *MemberStatus) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
|
|
@ -114,7 +114,6 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
|
||||||
// Pod found
|
// Pod found
|
||||||
if k8sutil.IsPodFailed(pod) {
|
if k8sutil.IsPodFailed(pod) {
|
||||||
// Wait some time before deleting the pod
|
// Wait some time before deleting the pod
|
||||||
log.Debug().Msgf("now: %v, then: %v", time.Now(), pod.GetCreationTimestamp())
|
|
||||||
if time.Now().After(pod.GetCreationTimestamp().Add(30 * time.Second)) {
|
if time.Now().After(pod.GetCreationTimestamp().Add(30 * time.Second)) {
|
||||||
if err := ib.KubeCli.CoreV1().Pods(ns).Delete(podName, nil); err != nil && !k8sutil.IsNotFound(err) {
|
if err := ib.KubeCli.CoreV1().Pods(ns).Delete(podName, nil); err != nil && !k8sutil.IsNotFound(err) {
|
||||||
log.Warn().Err(err).Msg("Failed to delete Image ID Pod")
|
log.Warn().Err(err).Msg("Failed to delete Image ID Pod")
|
||||||
|
@ -192,9 +191,9 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
|
||||||
serviceAccountName := ""
|
serviceAccountName := ""
|
||||||
|
|
||||||
env := make(map[string]k8sutil.EnvValue)
|
env := make(map[string]k8sutil.EnvValue)
|
||||||
if ib.Spec.HasLicenseKey() {
|
if ib.Spec.License.HasSecretName() {
|
||||||
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
|
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
|
||||||
SecretName: ib.Spec.GetLicenseKey(),
|
SecretName: ib.Spec.License.GetSecretName(),
|
||||||
SecretKey: constants.SecretKeyToken,
|
SecretKey: constants.SecretKeyToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,10 @@ import (
|
||||||
|
|
||||||
// ValidateLicenseKeySecret checks if the licens key secret exists and is valid
|
// ValidateLicenseKeySecret checks if the licens key secret exists and is valid
|
||||||
func (r *Resources) ValidateLicenseKeySecret() error {
|
func (r *Resources) ValidateLicenseKeySecret() error {
|
||||||
spec := r.context.GetSpec()
|
spec := r.context.GetSpec().License
|
||||||
|
|
||||||
if spec.HasLicenseKey() {
|
if spec.HasSecretName() {
|
||||||
secretName := spec.GetLicenseKey()
|
secretName := spec.GetSecretName()
|
||||||
|
|
||||||
kubecli := r.context.GetKubeCli()
|
kubecli := r.context.GetKubeCli()
|
||||||
ns := r.context.GetNamespace()
|
ns := r.context.GetNamespace()
|
||||||
|
|
|
@ -526,9 +526,9 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if spec.HasLicenseKey() {
|
if spec.License.HasSecretName() {
|
||||||
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
|
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
|
||||||
SecretName: spec.GetLicenseKey(),
|
SecretName: spec.License.GetSecretName(),
|
||||||
SecretKey: constants.SecretKeyToken,
|
SecretKey: constants.SecretKeyToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -599,9 +599,9 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
|
||||||
SecretKey: constants.SecretKeyToken,
|
SecretKey: constants.SecretKeyToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if spec.HasLicenseKey() {
|
if spec.License.HasSecretName() {
|
||||||
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
|
env[constants.EnvArangoLicenseKey] = k8sutil.EnvValue{
|
||||||
SecretName: spec.GetLicenseKey(),
|
SecretName: spec.License.GetSecretName(),
|
||||||
SecretKey: constants.SecretKeyToken,
|
SecretKey: constants.SecretKeyToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if [ -z $2 ]; then
|
LICENSE=$2
|
||||||
|
NS=$1
|
||||||
|
|
||||||
|
if [ -z $LICENSE ]; then
|
||||||
echo "No enterprise license set"
|
echo "No enterprise license set"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LICENSE=$(echo "${2}" | base64 -w 0 )
|
|
||||||
NS=$1
|
|
||||||
|
|
||||||
if [ -z $NS ]; then
|
if [ -z $NS ]; then
|
||||||
echo "Specify a namespace argument"
|
echo "Specify a namespace argument"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in a new issue