Skip to content

Commit 5c3df3f

Browse files
committed
GT-239 Fix License handling in case of broken license secret
1 parent c8248de commit 5c3df3f

File tree

7 files changed

+38
-82
lines changed

7 files changed

+38
-82
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- (Bugfix) Move Agency CommitIndex log message to Trace
2121
- (Feature) Force delete Pods which are stuck in init phase
2222
- (Bugfix) Do not tolerate False Bootstrap condition in UpToDate evaluation
23+
- (Bugfix) Fix License handling in case of broken license secret
2324

2425
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
2526
- (Feature) Add action progress

pkg/deployment/deployment_inspector.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,6 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
273273
return minInspectionInterval, errors.Wrapf(err, "Secret hash validation failed")
274274
}
275275

276-
// Check for LicenseKeySecret
277-
if err := d.resources.ValidateLicenseKeySecret(d.GetCachedStatus()); err != nil {
278-
return minInspectionInterval, errors.Wrapf(err, "License Key Secret invalid")
279-
}
280-
281276
// Is the deployment in a good state?
282277
if status.Conditions.IsTrue(api.ConditionTypeSecretsChanged) {
283278
return minInspectionInterval, errors.Newf("Secrets changed")

pkg/deployment/reconcile/action_set_license.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ func (a *actionLicenseSet) Start(ctx context.Context) (bool, error) {
5252
return true, nil
5353
}
5454

55-
l, ok := k8sutil.GetLicenseFromSecret(a.actionCtx.ACS().CurrentClusterCache(), spec.License.GetSecretName())
56-
57-
if !ok {
58-
return true, nil
55+
l, err := k8sutil.GetLicenseFromSecret(a.actionCtx.ACS().CurrentClusterCache(), spec.License.GetSecretName())
56+
if err != nil {
57+
return true, err
5958
}
6059

6160
if !l.V2.IsV2Set() {

pkg/deployment/reconcile/plan_builder_license.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ func (r *Reconciler) updateClusterLicense(ctx context.Context, apiObject k8sutil
3838
return nil
3939
}
4040

41-
l, ok := k8sutil.GetLicenseFromSecret(context.ACS().CurrentClusterCache(), spec.License.GetSecretName())
42-
if !ok {
43-
r.log.Str("secret", spec.Authentication.GetJWTSecretName()).Trace("Unable to find license secret key")
41+
l, err := k8sutil.GetLicenseFromSecret(context.ACS().CurrentClusterCache(), spec.License.GetSecretName())
42+
if err != nil {
43+
r.log.Err(err).Error("License secret error")
4444
return nil
4545
}
4646

4747
if !l.V2.IsV2Set() {
48-
r.log.Str("secret", spec.Authentication.GetJWTSecretName()).Trace("V2 License key is not set")
48+
r.log.Str("secret", spec.License.GetSecretName()).Error("V2 License key is not set")
4949
return nil
5050
}
5151

pkg/deployment/resources/license.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

pkg/util/k8sutil/license.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/arangodb/kube-arangodb/pkg/util"
2828
"github.com/arangodb/kube-arangodb/pkg/util/constants"
29+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2930
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret"
3031
)
3132

@@ -44,10 +45,10 @@ type LicenseSecret struct {
4445
V2 License
4546
}
4647

47-
func GetLicenseFromSecret(secret secret.Inspector, name string) (LicenseSecret, bool) {
48+
func GetLicenseFromSecret(secret secret.Inspector, name string) (LicenseSecret, error) {
4849
s, ok := secret.Secret().V1().GetSimple(name)
4950
if !ok {
50-
return LicenseSecret{}, false
51+
return LicenseSecret{}, errors.Newf("Secret %s not found", name)
5152
}
5253

5354
var l LicenseSecret
@@ -70,9 +71,12 @@ func GetLicenseFromSecret(secret secret.Inspector, name string) (LicenseSecret,
7071
} else {
7172
l.V2 = License(v2)
7273
}
74+
} else {
75+
return LicenseSecret{}, errors.Newf("Key (%s, %s or %s) is missing in the license secret (%s)",
76+
constants.SecretKeyToken, constants.SecretKeyV2License, constants.SecretKeyV2Token, name)
7377
}
7478

75-
return l, true
79+
return l, nil
7680
}
7781

7882
func isJSONBytes(s []byte) bool {

pkg/util/k8sutil/license_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func getLicenseFromSecret(t *testing.T, raw, encoded string) {
9898

9999
require.NoError(t, i.Refresh(context.Background()))
100100

101-
license, ok := GetLicenseFromSecret(i, n)
102-
require.True(t, ok)
101+
license, err := GetLicenseFromSecret(i, n)
102+
require.NoError(t, err)
103103

104104
require.Empty(t, license.V1)
105105
require.NotEmpty(t, license.V2)
@@ -111,8 +111,8 @@ func getLicenseFromSecret(t *testing.T, raw, encoded string) {
111111

112112
require.NoError(t, i.Refresh(context.Background()))
113113

114-
license, ok := GetLicenseFromSecret(i, n)
115-
require.True(t, ok)
114+
license, err := GetLicenseFromSecret(i, n)
115+
require.NoError(t, err)
116116

117117
require.Empty(t, license.V1)
118118
require.NotEmpty(t, license.V2)
@@ -126,8 +126,8 @@ func getLicenseFromSecret(t *testing.T, raw, encoded string) {
126126

127127
require.NoError(t, i.Refresh(context.Background()))
128128

129-
license, ok := GetLicenseFromSecret(i, n)
130-
require.True(t, ok)
129+
license, err := GetLicenseFromSecret(i, n)
130+
require.NoError(t, err)
131131

132132
require.Empty(t, license.V1)
133133
require.NotEmpty(t, license.V2)
@@ -139,12 +139,27 @@ func getLicenseFromSecret(t *testing.T, raw, encoded string) {
139139

140140
require.NoError(t, i.Refresh(context.Background()))
141141

142-
license, ok := GetLicenseFromSecret(i, n)
143-
require.True(t, ok)
142+
license, err := GetLicenseFromSecret(i, n)
143+
require.NoError(t, err)
144144

145145
require.Empty(t, license.V1)
146146
require.NotEmpty(t, license.V2)
147147
require.EqualValues(t, encoded, license.V2)
148148
})
149+
150+
t.Run("Non existing Secret license", func(t *testing.T) {
151+
require.NoError(t, i.Refresh(context.Background()))
152+
153+
_, err := GetLicenseFromSecret(i, "non-existing-secret")
154+
require.Error(t, err)
155+
})
156+
t.Run("Non existing license secret key", func(t *testing.T) {
157+
n := createLicenseSecret(t, c, "wrong-key", raw)
158+
159+
require.NoError(t, i.Refresh(context.Background()))
160+
161+
_, err := GetLicenseFromSecret(i, n)
162+
require.Error(t, err)
163+
})
149164
})
150165
}

0 commit comments

Comments
 (0)