-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Helm integration field structure (#55)
* Refactor Helm integration field structure
- Loading branch information
Showing
14 changed files
with
538 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
const ( | ||
replicatedSecretName = "replicated" | ||
replicatedIntegrationMockDataKey = "REPLICATED_INTEGRATION_MOCK_DATA" | ||
replicatedIntegrationEnabledKey = "REPLICATED_INTEGRATION_ENABLED" | ||
) | ||
|
||
var replicatedSecretLock = sync.Mutex{} | ||
|
||
func IsEnabled(ctx context.Context, clientset kubernetes.Interface, namespace string, license *kotsv1beta1.License) (bool, error) { | ||
if license == nil || license.Spec.LicenseType != "dev" { | ||
return false, nil | ||
} | ||
|
||
replicatedSecretLock.Lock() | ||
defer replicatedSecretLock.Unlock() | ||
|
||
secret, err := clientset.CoreV1().Secrets(namespace).Get(ctx, replicatedSecretName, metav1.GetOptions{}) | ||
if err != nil { | ||
if kuberneteserrors.IsNotFound(err) { | ||
return false, nil | ||
} | ||
return false, errors.Wrap(err, "failed to get replicated secret") | ||
} | ||
|
||
v, ok := secret.Data[replicatedIntegrationEnabledKey] | ||
if !ok || len(v) == 0 { | ||
return true, nil | ||
} | ||
|
||
enabled, _ := strconv.ParseBool(string(v)) | ||
return enabled, nil | ||
} | ||
|
||
func createReplicatedSecret(ctx context.Context, clientset kubernetes.Interface, namespace string, data map[string][]byte) error { | ||
secret := &corev1.Secret{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Secret", | ||
APIVersion: "v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: replicatedSecretName, | ||
Namespace: namespace, | ||
}, | ||
Data: data, | ||
} | ||
|
||
_, err := clientset.CoreV1().Secrets(namespace).Create(ctx, secret, metav1.CreateOptions{}) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create secret replicated") | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.