Skip to content

Commit

Permalink
refactor license
Browse files Browse the repository at this point in the history
  • Loading branch information
lingdie committed Oct 12, 2023
1 parent 6b01bf2 commit 8230111
Show file tree
Hide file tree
Showing 87 changed files with 370 additions and 4,153 deletions.
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
@@ -1,3 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
testbin/
bin/
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
*~
33 changes: 33 additions & 0 deletions controllers/license/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Build the manager binary
FROM golang:1.20 as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
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,31 @@ 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"
LicenseStatusPhaseSuccess 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
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

0 comments on commit 8230111

Please sign in to comment.