Skip to content

Commit

Permalink
modify some codes
Browse files Browse the repository at this point in the history
  • Loading branch information
yxxchange committed Aug 10, 2023
1 parent f59fa0c commit a897ef4
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 315 deletions.
8 changes: 4 additions & 4 deletions controllers/licenseissuer/.env
@@ -1,5 +1,5 @@
# set the environment variables when local testing
MONITOR= "true"
CAN_CONNECT_TO_EXTERNAL_NETWORK= "true"
MONGO_URI= "mongodb://root:fd4m9rg6@localhost:27017"
PASSWORD_SALT= "Ym1uazlranZscmIybmRxZmNreXQ4MzU1dWVtN3F3OWtpZDFhNGRvbmprbnNzMnFmNThuendrNDJtdzAyaG1wZw=="
MONITOR= ""
CAN_CONNECT_TO_EXTERNAL_NETWORK= ""
MONGO_URI= ""
PASSWORD_SALT= ""
3 changes: 3 additions & 0 deletions controllers/licenseissuer/deploy/Kubefile
Expand Up @@ -9,10 +9,13 @@ ENV canConnectToExternalNetwork "true"
ENV enableMonitor "true"
ENV MongoURI ""
ENV PasswordSalt ""
ENV Namespace "sealos-system"
ENV CollectorURL "https://license.sealos.io/collector"
ENV NotificationURL "https://license.sealos.io/notify"
ENV RegisterURL "https://license.sealos.io/register"
ENV CloudSyncURL "https://license.sealos.io/datasync"
ENV LicenseMonitorURL "https://license.sealos.io/license"



CMD ["chmod +x manifests/setup.sh && bash manifests/setup.sh"]
Expand Up @@ -8,6 +8,7 @@ stringData:
isMonitor: "{{ .enableMonitor }}"
MongoURI: "{{ .MongoURI }}"
PasswordSalt: "{{ .PasswordSalt }}"
Namespace: "{{ .Namespace }}"
---
apiVersion: v1
data:
Expand Down
141 changes: 8 additions & 133 deletions controllers/licenseissuer/deploy/manifests/deploy.yaml
Expand Up @@ -221,32 +221,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resources:
- namespaces
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- persistentvolumes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand All @@ -259,84 +233,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- infostream.sealos.io
resources:
- cloudsyncs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infostream.sealos.io
resources:
- cloudsyncs/finalizers
verbs:
- update
- apiGroups:
- infostream.sealos.io
resources:
- cloudsyncs/status
verbs:
- get
- patch
- update
- apiGroups:
- infostream.sealos.io
resources:
- collectors
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infostream.sealos.io
resources:
- collectors/finalizers
verbs:
- update
- apiGroups:
- infostream.sealos.io
resources:
- collectors/status
verbs:
- get
- patch
- update
- apiGroups:
- infostream.sealos.io
resources:
- launchers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infostream.sealos.io
resources:
- launchers/finalizers
verbs:
- update
- apiGroups:
- infostream.sealos.io
resources:
- launchers/status
verbs:
- get
- patch
- update
- apiGroups:
- infostream.sealos.io
resources:
Expand All @@ -363,32 +259,6 @@ rules:
- get
- patch
- update
- apiGroups:
- infostream.sealos.io
resources:
- notifications
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infostream.sealos.io
resources:
- notifications/finalizers
verbs:
- update
- apiGroups:
- infostream.sealos.io
resources:
- notifications/status
verbs:
- get
- patch
- update
- apiGroups:
- notification.sealos.io
resources:
Expand Down Expand Up @@ -583,7 +453,7 @@ spec:
resources:
limits:
cpu: 500m
memory: 64Mi
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
Expand Down Expand Up @@ -619,7 +489,12 @@ spec:
secretKeyRef:
key: PasswordSalt
name: licenseissuer-env
image: registry.cn-hangzhou.aliyuncs.com/fckc/cloud-controller:latest
- name: NAMESPACE
valueFrom:
secretKeyRef:
key: Namespace
name: licenseissuer-env
image: ghcr.io/labring/sealos-licenseissuer-controller:latest
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -639,7 +514,7 @@ spec:
memory: 1024Mi
requests:
cpu: 10m
memory: 64Mi
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
Expand Up @@ -73,17 +73,17 @@ func (r *LicenseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

// for notification
nq := &ntf.NoticeEventQueue{}
nm := ntf.NewNotificationManager(ctx, r.Client)
nm := ntf.NewNotificationManager(ctx, r.Client, r.logger, 1, 1)
nb := (&ntf.Builder{}).WithLevel(notificationv1.High).
WithTitle(util.LicenseNoticeTitle).WithFrom(util.Sealos).
WithType(ntf.General)
receiver := ntf.NewReceiver(ctx, r.Client).SetReceiver(req.Namespace)
receiver := ntf.NewReceiver(ctx, r.Client).AddReceiver(req.Namespace)

reader := &util.Reader{}
// get license

namespace := util.GetOptions().GetEnvOptions().Namespace
reader.Add(&r.license, types.NamespacedName{Namespace: req.Namespace, Name: util.LicenseName})
reader.Add(&r.configMap, types.NamespacedName{Namespace: util.SealosNamespace, Name: util.LicenseHistory})
reader.Add(&r.configMap, types.NamespacedName{Namespace: namespace, Name: util.LicenseHistory})

if err := reader.Read(ctx, r.Client); err != nil {
r.logger.Error(err, "failed to read resources...")
Expand Down Expand Up @@ -155,7 +155,10 @@ func (r *LicenseReconciler) Authorize(ctx context.Context) (string, error) {
return message, errors.New("invalid license")
}
// get account
id := types.NamespacedName{Namespace: util.SealosNamespace, Name: r.license.Spec.UID}
id := types.NamespacedName{
Namespace: util.GetOptions().GetEnvOptions().Namespace,
Name: r.license.Spec.UID,
}
err := r.Client.Get(ctx, id, &r.account)
if err != nil {
r.logger.Error(err, "failed to get account")
Expand Down
10 changes: 5 additions & 5 deletions controllers/licenseissuer/internal/controller/util/const.go
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
package util

const (
SealosNamespace = "sealos-system"
ClusterInfo = "cluster-info"
URLConfig = "url-config"
LicenseHistory = "license-history"
LicenseName = "license"
// SealosNamespace = "sealos-system"
ClusterInfo = "cluster-info"
URLConfig = "url-config"
LicenseHistory = "license-history"
LicenseName = "license"
// add more resource name here
)

Expand Down
Expand Up @@ -64,7 +64,7 @@ func (d *datasycn) sync(instance *TaskInstance) error {
}
// update configmap
err = d.updateConfigMap(instance, syncResponse, types.NamespacedName{
Namespace: SealosNamespace,
Namespace: GetOptions().GetEnvOptions().Namespace,
Name: URLConfig,
})

Expand Down
4 changes: 2 additions & 2 deletions controllers/licenseissuer/internal/controller/util/init.go
Expand Up @@ -142,7 +142,7 @@ func (t initTask) checkRegister(instance *TaskInstance) (bool, error) {
info := &corev1.Secret{}
err := instance.Get(instance.ctx, types.NamespacedName{
Name: ClusterInfo,
Namespace: SealosNamespace,
Namespace: GetOptions().GetEnvOptions().Namespace,
}, info)
if err != nil && apierrors.IsNotFound(err) {
return false, nil
Expand Down Expand Up @@ -171,7 +171,7 @@ func createClusterInfo() *corev1.Secret {
uuid := uuid.New().String()
secret := &corev1.Secret{}
secret.Name = ClusterInfo
secret.Namespace = SealosNamespace
secret.Namespace = GetOptions().GetEnvOptions().Namespace
secret.Data = map[string][]byte{
"uuid": []byte(uuid),
}
Expand Down

0 comments on commit a897ef4

Please sign in to comment.