Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cluster type license #4752

Merged
merged 19 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ on:

env:
# Common versions
GO_VERSION: "1.20"
GO_VERSION: "1.22"
DEFAULT_OWNER: "labring"
CRYPTOKEY: ${{ secrets.CONTROLLER_BUILD_CRYPTOKEY }}
LICENSE_KEY: ${{ secrets.LICENSE_KEY }}
Expand Down
20 changes: 11 additions & 9 deletions controllers/go.work
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
go 1.20
go 1.22

toolchain go1.22.3

use (
./account
./admission
./app
./db/adminer
./terminal
./node
./user
./resources
./license
./job/init
./job/heartbeat
./pkg
./job/init
./license
./node
./objectstorage
)
./pkg
./resources
./terminal
./user
)
293 changes: 291 additions & 2 deletions controllers/go.work.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions controllers/license/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ build: manifests generate fmt vet ## Build manager binary.
LD_FLAGS=""; \
[ -n "$(CRYPTOKEY)" ] && LD_FLAGS+="-X ${CONTROLLER_PKG}/crypto.encryptionKey=${CRYPTOKEY} -X ${CONTROLLER_PKG}/database.cryptoKey=${CRYPTOKEY}"; \
[ -n "$(LICENSE_KEY)" ] && LD_FLAGS+=" -X ${CONTROLLER_LICENSE}/util/key.EncryptionKey=${LICENSE_KEY}"; \
CGO_ENABLED=0 GOOS=linux go build -ldflags "$${LD_FLAGS}" -o bin/manager cmd/manager/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags "$${LD_FLAGS}" -o bin/manager cmd/manager/main.go


.PHONY: run
Expand Down Expand Up @@ -150,7 +150,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v4.2.0
CONTROLLER_TOOLS_VERSION ?= v0.8.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
13 changes: 13 additions & 0 deletions controllers/license/api/v1/license_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,25 @@ const (
LicenseStatusPhaseActive LicenseStatusPhase = "Active"
)

type ValidationCode int

const (
ValidationSuccess ValidationCode = iota
ValidationError
ValidationExpired
ValidationClusterIDMismatch
ValidationClusterInfoMismatch
)

// LicenseStatus defines the observed state of License
type LicenseStatus struct {
//+kubebuilder:validation:Enum=Pending;Failed;Active
//+kubebuilder:default=Pending
Phase LicenseStatusPhase `json:"phase,omitempty"`
ValidationCode ValidationCode `json:"validationCode,omitempty"`
Reason string `json:"reason,omitempty"`
ActivationTime metav1.Time `json:"activationTime,omitempty"`
ExpirationTime metav1.Time `json:"expirationTime,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
1 change: 1 addition & 0 deletions controllers/license/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controllers/license/cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func main() {
}
}()

if err = (&controller.LicenseReconciler{ClusterID: clusterID}).SetupWithManager(mgr, db, accountDB); err != nil {
if err = (&controller.LicenseReconciler{ClusterID: clusterID}).SetupWithManager(mgr, accountDB); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "License")
os.Exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ spec:
activationTime:
format: date-time
type: string
expirationTime:
format: date-time
type: string
phase:
default: Pending
enum:
- Pending
- Failed
- Active
type: string
reason:
type: string
validationCode:
type: integer
type: object
type: object
served: true
Expand Down
10 changes: 9 additions & 1 deletion controllers/license/config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2023 sealos.
# Copyright © 2024 sealos.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,14 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- license.sealos.io
resources:
Expand Down
24 changes: 21 additions & 3 deletions controllers/license/deploy/manifests/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ spec:
activationTime:
format: date-time
type: string
expirationTime:
format: date-time
type: string
phase:
default: Pending
enum:
- Pending
- Failed
- Active
type: string
reason:
type: string
validationCode:
type: integer
type: object
type: object
served: true
Expand Down Expand Up @@ -159,6 +166,14 @@ metadata:
creationTimestamp: null
name: license-manager-role
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- license.sealos.io
resources:
Expand Down Expand Up @@ -366,9 +381,12 @@ spec:
- --leader-elect
command:
- /manager
envFrom:
- configMapRef:
name: account-manager-env
env:
- name: MONGO_URI
valueFrom:
secretKeyRef:
key: MONGO_URI
name: license-secret
image: ghcr.io/labring/sealos-license-controller:latest
livenessProbe:
httpGet:
Expand Down
31 changes: 16 additions & 15 deletions controllers/license/go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/labring/sealos/controllers/license

go 1.20
go 1.22

require (
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/labring/sealos/controllers/account v0.0.0-00010101000000-000000000000
github.com/labring/sealos/controllers/pkg v0.0.0-20240402041753-99ca1d9840de
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4
github.com/onsi/ginkgo/v2 v2.10.0
github.com/onsi/gomega v1.27.8
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
go.mongodb.org/mongo-driver v1.12.1
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
Expand All @@ -18,7 +18,7 @@ require (
)

require (
cloud.google.com/go/compute v1.19.1 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.28 // indirect
Expand All @@ -30,16 +30,16 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-task/slim-sprig v2.20.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down Expand Up @@ -69,10 +69,10 @@ require (
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
Expand All @@ -89,7 +89,7 @@ require (
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.org/x/tools v0.21.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
Expand All @@ -101,11 +101,11 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.4 // indirect
gorm.io/gorm v1.25.5 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/apiextensions-apiserver v0.28.1 // indirect
k8s.io/component-base v0.28.2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
k8s.io/kube-openapi v0.0.0-20230918164632-68afd615200d // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand All @@ -122,5 +122,6 @@ replace (
k8s.io/apimachinery => k8s.io/apimachinery v0.25.6
k8s.io/client-go => k8s.io/client-go v0.25.6
k8s.io/component-base => k8s.io/component-base v0.25.6
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230525220651-2546d827e515
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.13.0
)
Loading
Loading