Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Iceber authored Jun 19, 2024
0 parents commit 079c8fe
Show file tree
Hide file tree
Showing 1,878 changed files with 775,518 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/clusterpedia
/bin
/plugins
28 changes: 28 additions & 0 deletions .github/workflows/push-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Push Images
on:
push:
branches:
- main
tags:
- v*
jobs:
images:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
fetch-depth: 0
- name: Set up qemu
uses: docker/setup-qemu-action@v2
with:
platforms: amd64,arm64
- name: Login registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push images
env:
ON_PLUGINS: true
run: |
REGISTRY="ghcr.io/$(echo ${{ github.repository_owner }}/clusterpedia | tr "A-Z" "a-z")" make push-images
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/bin
/plugins
.idea

# OSX trash
.DS_Storage

# apiserver local up cert trash
apiserver.local.config
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "clusterpedia"]
path = clusterpedia
url = https://github.com/clusterpedia-io/clusterpedia.git
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG BUILDER_IMAGE
FROM ${BUILDER_IMAGE} as builder

WORKDIR /plugin
COPY . .

ARG PLUGIN_NAME
RUN /builder.sh plugins ${PLUGIN_NAME}

FROM alpine:3.16
WORKDIR /plugins

ARG PLUGIN_NAME
COPY --from=builder /plugin/plugins/${PLUGIN_NAME} /plugins/${PLUGIN_NAME}
63 changes: 63 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
STORAGE_PLUGIN ?= $(shell sed -n '1p' go.mod | awk '{print $$2}' | awk -F'/' '{print $$NF}')

REGISTRY ?= "ghcr.io/clusterpedia-io/clusterpedia"
CLUSTERPEDIA_BUILDER_IMAGE = "ghcr.io/clusterpedia-io/clusterpedia/builder"
CLUSTERPEDIA_VERSIONS = v0.6.0-beta.1 v0.6.0
RELEASE_ARCHS ?= amd64 arm64

BUILDER_IMAGE ?= ""

VERSION = $(shell git describe --tags 2>/dev/null)
ifeq ($(VERSION),)
VERSION = v0.0.0
endif

BUILDER_TAG ?= $(shell echo $(BUILDER_IMAGE)|awk -F ':' '{ print $$2 }')
ifeq ($(BUILDER_TAG),)
BUILDER_TAG = latest
endif

GOARCH ?= $(shell go env GOARCH)

PWD = $(shell pwd)
CLUSTERPEDIA_REPO ?= $(PWD)/clusterpedia

build-plugin:
CLUSTERPEDIA_REPO=$(CLUSTERPEDIA_REPO) \
clusterpedia/hack/builder.sh plugins $(STORAGE_PLUGIN).so

build-components:
OUTPUT_DIR=$(PWD) ON_PLUGINS=true \
$(MAKE) -C clusterpedia all

image-plugin:
ifeq ($(BUILDER_IMAGE), "")
$(error BUILDER_IMAGE is not define)
endif

docker buildx build \
-t $(REGISTRY)/$(STORAGE_PLUGIN)-$(GOARCH):$(VERSION)-$(BUILDER_TAG) \
--platform=linux/$(GOARCH) \
--load \
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
--build-arg PLUGIN_NAME=$(STORAGE_PLUGIN).so .

push-images: clean-manifests
set -e; \
for version in $(CLUSTERPEDIA_VERSIONS); do \
images=""; \
for arch in $(RELEASE_ARCHS); do \
GOARCH=$$arch BUILDER_IMAGE=$(CLUSTERPEDIA_BUILDER_IMAGE):$$version BUILDER_TAG=$$version $(MAKE) image-plugin; \
image=$(REGISTRY)/$(STORAGE_PLUGIN)-$$arch:$(VERSION)-$$version; \
docker push $$image; \
images="$$images $$image"; \
done; \
docker manifest create $(REGISTRY)/$(STORAGE_PLUGIN):$(VERSION)-$$version $$images; \
docker manifest push $(REGISTRY)/$(STORAGE_PLUGIN):$(VERSION)-$$version; \
done;

clean-manifests:
for version in $(CLUSTERPEDIA_VERSIONS); do \
docker manifest rm $(REGISTRY)/$(STORAGE_PLUGIN):$(VERSION)-$$version 2>/dev/null; \
done; exit 0

50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Sample Storage
The storage layer plugin example replicates the implementation of the [internal storage layer](https://github.com/clusterpedia-io/clusterpedia/tree/main/pkg/storage/internalstorage), but it has the storage layer name - **sample storage**.

And you can see the storage layer information from the log when you list the resources.
```bash
$ STORAGE_PLUGINS=./plugins ./bin/apiserver --storage-name=sample-storage --storage-config=./config.yaml <... other flags>
...

I1107 11:35:14.450738 18955 resource_storage.go:195] "list resources in the sample storage" gvr="pods"
I1107 11:35:14.483075 18955 httplog.go:131] "HTTP" verb="GET" URI="/apis/clusterpedia.io/v1beta1/resources/api/v1/pods?limit=1" latency="40.270678ms" userAgent="curl/7.64.1" audit-ID="4ed69024-1848-4aa1-9f72-a9f1d7f36e3f" srcIP="127.0.0.1:58568" resp=200
```
`curl -k --cert client.crt --key client.key https://127.0.0.1:8443/apis/clusterpedia.io/v1beta1/resources/api/v1/pods\?limit\=1`

## Build and Run
`git clone` repo
```bash
$ git clone --recursive https://github.com/clusterpedia-io/sample-storage.git
$ cd sample-storage
```

build storage layer plugin
```bash
$ make build-plugin

$ # check plugin
$ file ./plugins/sample-storage.so
./plugins/sample-storage.so: Mach-O 64-bit dynamically linked shared library x86_64
```

build clusterpedia components for the debug
```bash
$ make build-components
$ ls -al ./bin
drwxr-xr-x 6 icebergu staff 192 11 7 11:17 .
drwxr-xr-x 16 icebergu staff 512 11 7 11:15 ..
-rwxr-xr-x 1 icebergu staff 90707488 11 7 11:15 apiserver
-rwxr-xr-x 1 icebergu staff 91896016 11 7 11:16 binding-apiserver
-rwxr-xr-x 1 icebergu staff 82769728 11 7 11:16 clustersynchro-manager
-rwxr-xr-x 1 icebergu staff 45682000 11 7 11:17 controller-manager
```

run clusterpedia apiserver
```bash
$ STORAGE_PLUGINS=./plugins ./bin/apiserver --storage-name=sample-storage --storage-config=./config.yaml <... other flags>
```

run clusterpedia clustersynchro-manager
```bash
$ STORAGE_PLUGINS=./plugins ./bin/clustersynchro-manager --storage-name=sample-storage --storage-config=./config.yaml <... other flags>
```
1 change: 1 addition & 0 deletions clusterpedia
Submodule clusterpedia added at 4608c8
10 changes: 10 additions & 0 deletions example-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type: mysql
host: 127.0.0.1
port: "3306"
user: root
password: dangerous0
database: clusterpedia
log:
stdout: true
colorful: true
slowThreshold: 100ms
61 changes: 61 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module github.com/clusterpedia-io/sample-storage

go 1.19

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/clusterpedia-io/api v0.0.0
github.com/clusterpedia-io/clusterpedia v0.0.0-00010101000000-000000000000
github.com/go-sql-driver/mysql v1.6.0
github.com/jackc/pgconn v1.13.0
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgx/v4 v4.17.2
github.com/jinzhu/configor v1.2.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gorm.io/datatypes v1.0.7
gorm.io/driver/mysql v1.4.4
gorm.io/driver/postgres v1.4.5
gorm.io/gorm v1.24.1
k8s.io/api v0.25.3
k8s.io/apimachinery v0.25.3
k8s.io/apiserver v0.25.3
k8s.io/component-base v0.25.3
k8s.io/klog/v2 v2.70.1
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.25.2 // indirect
k8s.io/kubernetes v1.25.2 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
github.com/clusterpedia-io/api => ./clusterpedia/staging/src/github.com/clusterpedia-io/api
github.com/clusterpedia-io/clusterpedia => ./clusterpedia
)
Loading

0 comments on commit 079c8fe

Please sign in to comment.