@@ -32,12 +32,15 @@ import (
3232
3333 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3434 "github.com/arangodb/kube-arangodb/pkg/deployment/client"
35- "github.com/arangodb/kube-arangodb/pkg/license_manager"
35+ "github.com/arangodb/kube-arangodb/pkg/deployment/pod"
36+ lmanager "github.com/arangodb/kube-arangodb/pkg/license_manager"
3637 "github.com/arangodb/kube-arangodb/pkg/platform/inventory"
3738 "github.com/arangodb/kube-arangodb/pkg/util"
39+ utilConstants "github.com/arangodb/kube-arangodb/pkg/util/constants"
3840 "github.com/arangodb/kube-arangodb/pkg/util/globals"
3941 ugrpc "github.com/arangodb/kube-arangodb/pkg/util/grpc"
4042 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
43+ "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/patcher"
4144)
4245
4346func newLicenseGenerateAction (action api.Action , actionCtx ActionContext ) Action {
@@ -84,7 +87,7 @@ func (a *actionLicenseGenerate) Start(ctx context.Context) (bool, error) {
8487 return true , nil
8588 }
8689
87- var req license_manager .LicenseRequest
90+ var req lmanager .LicenseRequest
8891 did , err := inventory .ExtractDeploymentID (ctx , c .Connection ())
8992 if err != nil {
9093 a .log .Err (err ).Error ("Unable to get deployment id" )
@@ -112,7 +115,7 @@ func (a *actionLicenseGenerate) Start(ctx context.Context) (bool, error) {
112115 req .TTL = util .NewType (ugrpc .NewObject (durationpb .New (q .Duration )))
113116 }
114117
115- lm , err := license_manager .NewClient (license_manager .ArangoLicenseManagerEndpoint , l .API .ClientID , l .API .ClientSecret )
118+ lm , err := lmanager .NewClient (lmanager .ArangoLicenseManagerEndpoint , l .API .ClientID , l .API .ClientSecret )
116119 if err != nil {
117120 a .log .Err (err ).Error ("Unable to create inventory client" )
118121 return true , nil
@@ -167,13 +170,60 @@ func (a *actionLicenseGenerate) Start(ctx context.Context) (bool, error) {
167170 expires = time .Now ().Add (time .Duration (math .Round (float64 (time .Until (license .Expires ())) * api .LicenseExpirationGraceRatio )))
168171 }
169172
173+ cache := a .actionCtx .ACS ().CurrentClusterCache ()
174+
175+ if s , ok := cache .Secret ().V1 ().GetSimple (pod .GetLicenseRegistryCredentialsSecretName (a .actionCtx .GetName ())); ok {
176+ if string (util .Optional (s .Data , utilConstants .ChecksumKey , []byte {})) != l .API .Hash () {
177+ // Update
178+
179+ token , err := lm .RegistryConfig (ctx , lmanager .ArangoLicenseManagerEndpoint , l .API .ClientID , & l .API .ClientSecret , lmanager .StageDev , lmanager .StageQA , lmanager .StagePrd )
180+ if err != nil {
181+ a .log .Err (err ).Debug ("Failed to generate License Registry" )
182+ return true , nil
183+ }
184+
185+ if _ , _ , err := patcher .Patcher [* core.Secret ](ctx , cache .Client ().Kubernetes ().CoreV1 ().Secrets (a .actionCtx .GetNamespace ()), s , meta.PatchOptions {},
186+ patcher .PatchSecretData (map [string ][]byte {
187+ core .DockerConfigJsonKey : token ,
188+ utilConstants .ChecksumKey : []byte (l .API .Hash ()),
189+ })); err != nil {
190+ a .log .Err (err ).Debug ("Failed to patch License Secret" )
191+ return true , nil
192+ }
193+ }
194+ } else {
195+ token , err := lm .RegistryConfig (ctx , lmanager .ArangoLicenseManagerEndpoint , l .API .ClientID , & l .API .ClientSecret , lmanager .StageDev , lmanager .StageQA , lmanager .StagePrd )
196+ if err != nil {
197+ a .log .Err (err ).Debug ("Failed to generate License Registry" )
198+ return true , nil
199+ }
200+
201+ if _ , err := cache .Client ().Kubernetes ().CoreV1 ().Secrets (a .actionCtx .GetNamespace ()).Create (ctx , & core.Secret {
202+ ObjectMeta : meta.ObjectMeta {
203+ Name : pod .GetLicenseRegistryCredentialsSecretName (a .actionCtx .GetName ()),
204+ OwnerReferences : []meta.OwnerReference {
205+ a .actionCtx .GetAPIObject ().AsOwner (),
206+ },
207+ },
208+ Data : map [string ][]byte {
209+ core .DockerConfigJsonKey : token ,
210+ utilConstants .ChecksumKey : []byte (l .API .Hash ()),
211+ },
212+ Type : core .SecretTypeDockerConfigJson ,
213+ }, meta.CreateOptions {}); err != nil {
214+ a .log .Err (err ).Debug ("Failed to create License Secret" )
215+ return true , nil
216+ }
217+ }
218+
170219 if err := a .actionCtx .WithStatusUpdate (ctx , func (s * api.DeploymentStatus ) bool {
171220 s .License = & api.DeploymentStatusLicense {
172221 ID : generatedLicense .ID ,
173222 Hash : license .Hash ,
174223 Expires : meta.Time {Time : license .Expires ()},
175224 Mode : api .LicenseModeAPI ,
176225 Regenerate : meta.Time {Time : expires },
226+ InputHash : l .API .Hash (),
177227 }
178228 return true
179229 }); err != nil {
0 commit comments