Skip to content

Commit

Permalink
support free license for admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
yxxchange committed Jul 27, 2023
1 parent 0adc21d commit a900ae0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion controllers/licenseissuer/deploy/manifests/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ spec:
secretKeyRef:
key: isMonitor
name: licenseissuer-env
image: ghcr.io/labring/sealos-licenseissuer-controller:latest
image: registry.cn-hangzhou.aliyuncs.com/fckc/cloud-controller:v3.3.5
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controller
import (
"context"
"os"
"time"

"github.com/go-logr/logr"
accountv1 "github.com/labring/sealos/controllers/account/api/v1"
Expand Down Expand Up @@ -128,27 +127,15 @@ func (r *LicenseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
} else {
payload, ok = issuer.LicenseCheckOnInternalNetwork(license)
}

// pre-check for license
if !ok {
pack := issuer.NewNotificationPackage(issuer.LicenseNoticeTitle, issuer.SEALOS, issuer.InvalidLicenseMessage)
issuer.SubmitNotificationWithUser(ctx, r.Client, req.Namespace, pack)
r.logger.Info("invalid license")
return ctrl.Result{}, r.Client.Delete(ctx, &license)
}
// check license creat time
creatTime, err := issuer.InterfaceToInt64(payload[issuer.CreatTimeField])
if err != nil {
r.logger.Error(err, "failed to convert license creat time")
pack := issuer.NewNotificationPackage(issuer.LicenseNoticeTitle, issuer.SEALOS, issuer.InvalidLicenseMessage)
issuer.SubmitNotificationWithUser(ctx, r.Client, req.Namespace, pack)
return ctrl.Result{}, r.Client.Delete(ctx, &license)
}
if time.Unix(creatTime, 0).Add(issuer.LicenseLifetime).Before(time.Now()) {
pack := issuer.NewNotificationPackage(issuer.LicenseNoticeTitle, issuer.SEALOS, issuer.ExpiredLicenseMessage)
issuer.SubmitNotificationWithUser(ctx, r.Client, req.Namespace, pack)
r.logger.Info("expired license")
return ctrl.Result{}, r.Client.Delete(ctx, &license)
}

// recharge
(&issuer.WriteEventBuilder{}).WithCallback(func() error {
if !issuer.ContainsFields(payload, issuer.AmountField) {
Expand Down
6 changes: 6 additions & 0 deletions deploy/cloud/manifests/admin-user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: user.sealos.io/v1
kind: User
metadata:
name: admin
spec:
csrExpirationSeconds: 7200
7 changes: 7 additions & 0 deletions deploy/cloud/manifests/free-license.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: infostream.sealos.io/v1
kind: License
metadata:
name: license
spec:
uid: admin
token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJTZWFsb3MiLCJpYXQiOjE2OTA0NDU5NjIsImFtdCI6MjAwMH0.ZzZfPRbNiNvRBLMn5FGJeKitRPHmUHZ1qvnGdJUIbIH1L5mQ4yECzvvsa5S8-OTqF6HXmrw9QmFcQOjoz5GpqjqrqXdH2H-JDXFGNNAib2J9UmLFmtV1BVm3zReucfK-bOY5NiWOr5wplEVwkoUKNPHLY5Mw142y9J62vELE-XW-hb3xcmWjLTPVRYgMqk0KEi7Z7cQ_rS0QgJh1Rqb2WS6AKz2ILE5J8XUhhhUva0nCEyLzE-I8oZtV6kugQy8YjWI-SjfneFOLI8-Pg40vry6DZZ-_J_9QmjkUlZx0YNMRiRA5yg2yWeMEzVnam9L310TJgu6Od-bEUijsfOcZyw"
8 changes: 8 additions & 0 deletions deploy/cloud/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ function install {
# apply notifications crd
kubectl apply -f manifests/notifications_crd.yaml

# apply admin user
kubectl apply -f manifests/admin-user.yaml
# ensure admin namespace and admin account created
sleep 5

# apply free license for admin
kubectl apply -f manifests/free-license.yaml

# create tls secret
create_tls_secret $cloudDomain

Expand Down

0 comments on commit a900ae0

Please sign in to comment.