-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
147 changed files
with
7,961 additions
and
1,802 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
find . -name "*.go" | xargs gofmt -w | ||
git diff --name-only --exit-code || if [ $? != 0 ]; then echo "Notice: gofmt check failed,please gofmt before pr." && exit 1; fi | ||
echo "gofmt check pass." | ||
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
GOARCH=${{ matrix.goarch }} | ||
for file in `find . -name go.mod`; do | ||
dirpath=$(dirname $file) | ||
echo $dirpath | ||
|
||
# package oracle needs golang >= v1.17 | ||
if [ "oracle" = $(basename $dirpath) ]; then | ||
if ! go version|grep -q "1.17"; then | ||
echo "ignore oracle as go version: $(go version)" | ||
continue 1 | ||
fi | ||
fi | ||
|
||
# package kuhecm needs golang >= v1.18 | ||
if [ "kubecm" = $(basename $dirpath) ]; then | ||
if ! go version|grep -q "1.18"; then | ||
echo "ignore kubecm as go version: $(go version)" | ||
continue 1 | ||
fi | ||
fi | ||
|
||
# package example needs golang >= v1.18 | ||
if [ "example" = $(basename $dirpath) ]; then | ||
if ! go version|grep -q "1.18"; then | ||
echo "ignore example as go version: $(go version)" | ||
continue 1 | ||
fi | ||
fi | ||
|
||
cd $dirpath | ||
go mod tidy | ||
go build ./... | ||
go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1 | ||
if grep -q "/gogf/gf/.*/v2" go.mod; then | ||
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out | ||
fi | ||
cd - | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# kubecm | ||
Package `kubecm` implements GoFrame `gcfg.Adapter` using kubernetes configmap. | ||
|
||
# Limit | ||
|
||
```go | ||
glang version >= v.18 | ||
``` | ||
|
||
# Installation | ||
``` | ||
go get -u github.com/gogf/gf/contrib/config/kubecm/v2 | ||
``` | ||
|
||
# Example | ||
|
||
## Example configmap | ||
```yaml | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: test-configmap | ||
data: | ||
config.yaml: | | ||
# HTTP service. | ||
server: | ||
address: ":8888" | ||
openapiPath: "/api.json" | ||
swaggerPath: "/swagger" | ||
accessLogEnabled: true | ||
``` | ||
Note the configmap name `test-configmap`, and its item name in data `config.yaml`. | ||
|
||
|
||
## Create a custom boot package | ||
|
||
It is strongly recommended creating a boot package, | ||
which sets the Adapter of default configuration instance. | ||
|
||
### Running in pod (common scenario) | ||
```go | ||
package boot | ||
import ( | ||
"github.com/gogf/gf/contrib/config/kubecm/v2" | ||
"github.com/gogf/gf/v2/frame/g" | ||
"github.com/gogf/gf/v2/os/gctx" | ||
) | ||
const ( | ||
configmapName = "test-configmap" | ||
dataItemInConfigmap = "config.yaml" | ||
) | ||
func init() { | ||
var ( | ||
err error | ||
ctx = gctx.GetInitCtx() | ||
) | ||
// Create kubecm Client that implements gcfg.Adapter. | ||
adapter, err := kubecm.New(gctx.GetInitCtx(), kubecm.Config{ | ||
ConfigMap: configmapName, | ||
DataItem: dataItemInConfigmap, | ||
}) | ||
if err != nil { | ||
g.Log().Fatalf(ctx, `%+v`, err) | ||
} | ||
|
||
// Change the adapter of default configuration instance. | ||
g.Cfg().SetAdapter(adapter) | ||
} | ||
``` | ||
|
||
### Running out of pod (often testing scenario) | ||
```go | ||
package boot | ||
|
||
import ( | ||
"github.com/gogf/gf/contrib/config/kubecm/v2" | ||
"github.com/gogf/gf/v2/frame/g" | ||
"github.com/gogf/gf/v2/os/gctx" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
const ( | ||
namespace = "default" | ||
configmapName = "test-configmap" | ||
dataItemInConfigmap = "config.yaml" | ||
kubeConfigFilePathJohn = `/Users/john/.kube/config` | ||
) | ||
|
||
func init() { | ||
var ( | ||
err error | ||
ctx = gctx.GetInitCtx() | ||
kubeClient *kubernetes.Clientset | ||
) | ||
// Create kubernetes client. | ||
// It is optional creating kube client when its is running in pod. | ||
kubeClient, err = kubecm.NewKubeClientFromPath(ctx, kubeConfigFilePathJohn) | ||
if err != nil { | ||
g.Log().Fatalf(ctx, `%+v`, err) | ||
} | ||
// Create kubecm Client that implements gcfg.Adapter. | ||
adapter, err := kubecm.New(gctx.GetInitCtx(), kubecm.Config{ | ||
ConfigMap: configmapName, | ||
DataItem: dataItemInConfigmap, | ||
Namespace: namespace, // It is optional specifying namespace when its is running in pod. | ||
KubeClient: kubeClient, // It is optional specifying kube client when its is running in pod. | ||
}) | ||
if err != nil { | ||
g.Log().Fatalf(ctx, `%+v`, err) | ||
} | ||
|
||
// Change the adapter of default configuration instance. | ||
g.Cfg().SetAdapter(adapter) | ||
|
||
} | ||
``` | ||
|
||
## Import boot package in top of main | ||
|
||
It is strongly recommended import your boot package in top of your `main.go`. | ||
|
||
Note the top `import`: `_ "github.com/gogf/gf/example/config/kubecm/boot_in_pod"` . | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
_ "github.com/gogf/gf/example/config/kubecm/boot_in_pod" | ||
|
||
"github.com/gogf/gf/v2/frame/g" | ||
"github.com/gogf/gf/v2/os/gctx" | ||
) | ||
|
||
func main() { | ||
var ctx = gctx.GetInitCtx() | ||
|
||
// Available checks. | ||
g.Dump(g.Cfg().Available(ctx)) | ||
|
||
// All key-value configurations. | ||
g.Dump(g.Cfg().Data(ctx)) | ||
|
||
// Retrieve certain value by key. | ||
g.Dump(g.Cfg().MustGet(ctx, "server.address")) | ||
} | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module github.com/gogf/gf/contrib/config/kubecm/v2 | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/gogf/gf/v2 v2.0.0 | ||
k8s.io/api v0.25.2 | ||
k8s.io/apimachinery v0.25.2 | ||
k8s.io/client-go v0.25.2 | ||
) | ||
|
||
require ( | ||
github.com/BurntSushi/toml v1.1.0 // indirect | ||
github.com/PuerkitoBio/purell v1.1.1 // indirect | ||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/clbanning/mxj/v2 v2.5.5 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
github.com/emicklei/go-restful/v3 v3.8.0 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/fsnotify/fsnotify v1.5.4 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.19.5 // indirect | ||
github.com/go-openapi/swag v0.19.14 // indirect | ||
github.com/go-redis/redis/v8 v8.11.5 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/gofuzz v1.1.0 // indirect | ||
github.com/gorilla/websocket v1.5.0 // indirect | ||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect | ||
github.com/imdario/mergo v0.3.6 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mattn/go-colorable v0.1.9 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/mattn/go-runewidth v0.0.9 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/olekukonko/tablewriter v0.0.5 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
go.opentelemetry.io/otel v1.7.0 // indirect | ||
go.opentelemetry.io/otel/sdk v1.7.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.7.0 // indirect | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect | ||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect | ||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect | ||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/klog/v2 v2.70.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // 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.2.0 // indirect | ||
) | ||
|
||
replace github.com/gogf/gf/v2 => ../../../ |
Oops, something went wrong.