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

refactor license #4086

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- { name: db-adminer, path: db/adminer }
- { name: resources, path: resources }
- { name: resources-metering, path: resources/metering }
- { name: licenseissuer, path: licenseissuer }
- { name: license, path: license }
- { name: node, path: node }
- { name: admission, path: admission }
steps:
Expand Down Expand Up @@ -186,7 +186,7 @@ jobs:
- { name: db-adminer, path: db/adminer }
- { name: resources, path: resources }
- { name: resources-metering, path: resources/metering }
- { name: licenseissuer, path: licenseissuer }
- { name: license, path: license }
- { name: node, path: node }
- { name: admission, path: admission }
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*.dll
*.so
*.dylib
bin
testbin/*
bin/*
Dockerfile.cross

# Test binary, build with `go test -c`
Expand All @@ -21,6 +20,7 @@ Dockerfile.cross

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ COPY bin/controller-licenseissuer-$TARGETARCH /manager
COPY bin/preset-$TARGETARCH /preset
COPY bin/launcher-$TARGETARCH /launcher

ENTRYPOINT ["/launcher"]
ENTRYPOINT ["/launcher"]
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/labring/sealos-licenseissuer-controller:latest
IMG ?= ghcr.io/labring/sealos-license-controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.1

include .env
export

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -64,21 +61,21 @@ test: manifests generate fmt vet envtest ## Run tests.

##@ Build

.PHONY: build
.PHONY: build
CONTROLLER_PKG=github.com/labring/sealos/controllers/pkg
CONTROLLER_LICENSEISSUER=github.com/labring/sealos/controllers/licenseissuer/internal/controller
CONTROLLER_LICENSE=github.com/labring/sealos/controllers/license/internal/controller
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_LICENSEISSUER}/util.Key=${LICENSE_KEY}"; \
CGO_ENABLED=0 GOOS=linux go build -ldflags "$${LD_FLAGS}" -o bin/manager cmd/main.go && \
CGO_ENABLED=0 GOOS=linux go build -o bin/preset-${GOARCH} preset/main.go && chmod +x bin/preset-${GOARCH} && \
CGO_ENABLED=0 GOOS=linux go build -o bin/launcher-${GOARCH} launcher/main.go && chmod +x bin/launcher-${GOARCH}
[ -n "$(LICENSE_KEY)" ] && LD_FLAGS+=" -X ${CONTROLLER_LICENSE}/util.Key=${LICENSE_KEY}"; \
CGO_ENABLED=0 GOOS=linux go build -ldflags "$${LD_FLAGS}" -o bin/manager cmd/manager/main.go && \
CGO_ENABLED=0 GOOS=linux go build -o bin/preset-${GOARCH} cmd/preset/main.go && chmod +x bin/preset-${GOARCH} && \
CGO_ENABLED=0 GOOS=linux go build -o bin/launcher-${GOARCH} cmd/launcher/main.go && chmod +x bin/launcher-${GOARCH}


.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
go run ./cmd/manager/main.go

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
Expand Down
20 changes: 20 additions & 0 deletions controllers/license/PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: sealos.io
layout:
- go.kubebuilder.io/v4
projectName: license
repo: github.com/labring/sealos/controllers/license
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: sealos.io
group: license
kind: License
path: github.com/labring/sealos/controllers/license/api/v1
version: v1
version: "3"
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# licenseissuer-controller

LicenseIssuer is a Operator that authorizes the use of a license for a given user.

In this module, there are three binaries in total, which are launcher, preset, and manager.

Launcher is a starter responsible for launching preset and manager.

Preset is an idempotent binary program responsible for registering the root user in the database, and the root user has a certain amount of free quota.

Manager is used to create license resources and activate the license injected into the cluster.
# license
// TODO(user): Add simple overview of use/purpose

## Description
// TODO(user): An in-depth paragraph about your project and overview of use
Expand All @@ -27,13 +18,13 @@ kubectl apply -f config/samples/
2. Build and push your image to the location specified by `IMG`:

```sh
make docker-build docker-push IMG=<some-registry>/licenseissuer-controller:tag
make docker-build docker-push IMG=<some-registry>/license:tag
```

3. Deploy the controller to the cluster with the image specified by `IMG`:

```sh
make deploy IMG=<some-registry>/licenseissuer-controller:tag
make deploy IMG=<some-registry>/license:tag
```

### Uninstall CRDs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the infostream v1 API group
// Package v1 contains API Schema definitions for the license v1 API group
// +kubebuilder:object:generate=true
// +groupName=infostream.sealos.io
// +groupName=license.sealos.io
package v1

import (
Expand All @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "infostream.sealos.io", Version: "v1"}
GroupVersion = schema.GroupVersion{Group: "license.sealos.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,34 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
type Type string

const (
AccountLicenseType Type = "Account"
ClusterLicenseType Type = "Cluster"
)

// LicenseSpec defines the desired state of License
type LicenseSpec struct {
UID string `json:"uid,omitempty"`
//+kubebuilder:validation:Enum=Account;Cluster
Type Type `json:"type,omitempty"`
Token string `json:"token,omitempty"`
Key string `json:"key,omitempty"`
}

type LicenseStatusPhase string

const (
LicenseStatusPhasePending LicenseStatusPhase = "Pending"
LicenseStatusPhaseFailed LicenseStatusPhase = "Failed"
LicenseStatusPhaseActive LicenseStatusPhase = "Active"
)

// LicenseStatus defines the observed state of License
type LicenseStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
//+kubebuilder:validation:Enum=Pending;Failed;Active
//+kubebuilder:default=Pending
Phase LicenseStatusPhase `json:"phase,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down

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

5 changes: 5 additions & 0 deletions controllers/license/cmd/launcher/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
// TODO do something
}
Loading
Loading