Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] License ArangoDeployment Fetcher #1485

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- (Bugfix) Proper handling of --agency.retries argument
- (Documentation) Do not use field type name for field URL hash
- (Maintenance) Bump Go to 1.20.11
- (Feature) License ArangoDeployment Fetcher

## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
Expand Down
10 changes: 0 additions & 10 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile"
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme"
"github.com/arangodb/kube-arangodb/pkg/license"
"github.com/arangodb/kube-arangodb/pkg/logging"
"github.com/arangodb/kube-arangodb/pkg/metrics/collector"
"github.com/arangodb/kube-arangodb/pkg/operator"
Expand Down Expand Up @@ -172,8 +171,6 @@ var (
backupProbe probe.ReadyProbe
appsProbe probe.ReadyProbe
k2KClusterSyncProbe probe.ReadyProbe

licenseConfig license.Config
)

func init() {
Expand Down Expand Up @@ -239,9 +236,6 @@ func init() {
if err := reconcile.ActionsConfigGlobal.Init(&cmdMain); err != nil {
panic(err.Error())
}
if err := licenseConfig.Init(&cmdMain); err != nil {
panic(err.Error())
}
}

func Execute() int {
Expand Down Expand Up @@ -315,10 +309,6 @@ func executeMain(cmd *cobra.Command, args []string) {
})
}

if err := licenseConfig.Enable(); err != nil {
logger.Err(err).Fatal("Failed to License checker process")
}

logger.Info("nice to meet you")

// Print all enabled featured
Expand Down
91 changes: 0 additions & 91 deletions pkg/license/config.go

This file was deleted.

12 changes: 10 additions & 2 deletions pkg/license/license.community.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@

package license

import "github.com/arangodb/kube-arangodb/pkg/util/assertion"
import (
"context"

func checkLicense(license string) License {
"github.com/arangodb/kube-arangodb/pkg/util/assertion"
)

func NewLicense(loader Loader) License {
return emptyLicense{}
}

type emptyLicense struct {
}

func (e emptyLicense) Refresh(ctx context.Context) error {
return nil
}

// Validate for the community returns that license is always missing, as it should be not used
func (e emptyLicense) Validate(feature Feature, subFeatures ...Feature) Status {
assertion.Assert(true, assertion.CommunityLicenseCheckKey, "Feature %s has been validated in the community version", feature)
Expand Down
6 changes: 6 additions & 0 deletions pkg/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

package license

import (
"context"
)

type Status int

const (
Expand Down Expand Up @@ -79,4 +83,6 @@ type License interface {
// -- for each subFeature defined in subFeatures:
// --- checks if subFeature or '*' is in the list of License Feature enabled SubFeatures
Validate(feature Feature, subFeatures ...Feature) Status

Refresh(ctx context.Context) error
}
101 changes: 101 additions & 0 deletions pkg/license/loader_arangodeployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// 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 license

import (
"context"
"encoding/base64"

"k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)

func NewArengoDeploymentLicenseLoader(factory kclient.Factory, namespace, name string) Loader {
return arangoDeploymentLicenseLoader{
factory: factory,
namespace: namespace,
name: name,
}
}

type arangoDeploymentLicenseLoader struct {
factory kclient.Factory

namespace, name string
}

func (a arangoDeploymentLicenseLoader) Refresh(ctx context.Context) (string, bool, error) {
client, ok := a.factory.Client()
if !ok {
return "", false, nil
}

deployment, err := client.Arango().DatabaseV1().ArangoDeployments(a.namespace).Get(ctx, a.name, meta.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return "", false, nil
}

return "", false, err
}

spec := deployment.GetAcceptedSpec()

if !spec.License.HasSecretName() {
return "", false, nil
}

secret, err := client.Kubernetes().CoreV1().Secrets(deployment.GetNamespace()).Get(ctx, spec.License.GetSecretName(), meta.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return "", false, nil
}

return "", false, err
}

var licenseData []byte

if lic, ok := secret.Data[constants.SecretKeyV2License]; ok {
licenseData = lic
} else if lic2, ok := secret.Data[constants.SecretKeyV2Token]; ok {
licenseData = lic2
}

if len(licenseData) == 0 {
return "", false, nil
}

if !k8sutil.IsJSON(licenseData) {
d, err := base64.StdEncoding.DecodeString(string(licenseData))
if err != nil {
return "", false, err
}

licenseData = d
}

return string(licenseData), true, nil
}
35 changes: 0 additions & 35 deletions pkg/license/loader_constant.go

This file was deleted.

36 changes: 0 additions & 36 deletions pkg/license/loader_disabled.go

This file was deleted.

Loading