Skip to content

Commit

Permalink
Merge pull request #30 from Somefive/feat/dynamic-api
Browse files Browse the repository at this point in the history
Feat: add dynamic api
  • Loading branch information
Somefive authored Nov 18, 2022
2 parents c431248 + 51eb282 commit 8026c15
Show file tree
Hide file tree
Showing 38 changed files with 2,302 additions and 856 deletions.
30 changes: 27 additions & 3 deletions charts/templates/apiservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: APIService
metadata:
name: v1alpha1.prism.oam.dev
labels:
api: kuebvela-vela-prism
api: kubevela-vela-prism
apiserver: "true"
{{- include "vela-prism.labels" . | nindent 4 }}
spec:
Expand All @@ -25,7 +25,7 @@ kind: APIService
metadata:
name: v1alpha1.o11y.prism.oam.dev
labels:
api: kuebvela-vela-prism
api: kubevela-vela-prism
apiserver: "true"
{{- include "vela-prism.labels" . | nindent 4 }}
spec:
Expand All @@ -40,4 +40,28 @@ spec:
insecureSkipTLSVerify: {{ not .Values.secureTLS.enabled }}
{{ if .Values.secureTLS.enabled }}
caBundle: Cg==
{{ end }}
{{ end }}
---
{{ if .Values.dynamicAPI.enabled }}
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1alpha1.dynamic.prism.oam.dev
labels:
api: kubevela-vela-prism
apiserver: "true"
{{- include "vela-prism.labels" . | nindent 4 }}
spec:
version: v1alpha1
group: dynamic.prism.oam.dev
groupPriorityMinimum: 2000
service:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
port: {{ .Values.port }}
versionPriority: 10
insecureSkipTLSVerify: {{ not .Values.secureTLS.enabled }}
{{ if .Values.secureTLS.enabled }}
caBundle: Cg==
{{ end }}
{{ end }}
11 changes: 11 additions & 0 deletions charts/templates/secure-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ spec:
- --secret-namespace={{ .Release.Namespace }}
- --secret-name={{ .Release.Name }}
- --target-APIService=v1alpha1.o11y.prism.oam.dev
{{ if .Values.dynamicAPI.enabled }}
- name: patch-dynamic
image: {{ .Values.imageRegistry }}{{ .Values.secureTLS.certPatch.image.repository }}:{{ .Values.secureTLS.certPatch.image.tag }}
imagePullPolicy: {{ .Values.secureTLS.certPatch.image.pullPolicy }}
command:
- /patch
args:
- --secret-namespace={{ .Release.Namespace }}
- --secret-name={{ .Release.Name }}
- --target-APIService=v1alpha1.dynamic.prism.oam.dev
{{ end }}
restartPolicy: OnFailure
serviceAccountName: {{ .Release.Name }}-certpatch
securityContext:
Expand Down
5 changes: 5 additions & 0 deletions charts/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ rules:
- apiGroups: ["cluster.open-cluster-management.io"]
resources: ["managedclusters"]
verbs: ["get", "watch", "list"]
{{ if .Values.dynamicAPI.enabled }}
- apiGroups: ["*"]
resources: ["*"]
verbs: ["get", "list", "create", "patch", "update", "delete", "watch"]
{{ end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
5 changes: 4 additions & 1 deletion charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ secureTLS:
image:
repository: oamdev/cluster-gateway
tag: v1.4.0
pullPolicy: IfNotPresent
pullPolicy: IfNotPresent

dynamicAPI:
enabled: true
17 changes: 8 additions & 9 deletions cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package main

import (
"k8s.io/klog/v2"
"k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/apiserver-runtime/pkg/builder"

apprtv1alpha1 "github.com/kubevela/prism/pkg/apis/applicationresourcetracker/v1alpha1"
Expand All @@ -26,6 +26,8 @@ import (
grafanav1alpha1 "github.com/kubevela/prism/pkg/apis/o11y/grafana/v1alpha1"
grafanadashboardv1alpha1 "github.com/kubevela/prism/pkg/apis/o11y/grafanadashboard/v1alpha1"
grafanadatasourcev1alpha1 "github.com/kubevela/prism/pkg/apis/o11y/grafanadatasource/v1alpha1"
"github.com/kubevela/prism/pkg/cue"
apiserver "github.com/kubevela/prism/pkg/dynamicapiserver"
apiserveroptions "github.com/kubevela/prism/pkg/util/apiserver/options"
"github.com/kubevela/prism/pkg/util/log"
"github.com/kubevela/prism/pkg/util/singleton"
Expand All @@ -42,17 +44,14 @@ func main() {
WithResource(&grafanav1alpha1.Grafana{}).
WithResource(&grafanadatasourcev1alpha1.GrafanaDatasource{}).
WithResource(&grafanadashboardv1alpha1.GrafanaDashboard{}).
WithConfigFns(apiserveroptions.WrapConfig).
WithPostStartHook("init-master-loopback-client", singleton.InitLoopbackClient).
WithConfigFns(apiserveroptions.WrapConfig, singleton.InitServerConfig).
WithServerFns(cue.RegisterGenericAPIServer, singleton.InitGenericAPIServer).
WithPostStartHook("start-dynamic-server", apiserver.StartDefaultDynamicAPIServer).
Build()
if err != nil {
klog.Fatal(err)
}
runtime.Must(err)
log.AddLogFlags(cmd)
apiserveroptions.AddServerRunFlags(cmd.Flags())
clusterv1alpha1.AddClusterFlags(cmd.Flags())
o11yconfig.AddObservabilityFlags(cmd.Flags())
if err = cmd.Execute(); err != nil {
klog.Fatal(err)
}
runtime.Must(cmd.Execute())
}
115 changes: 60 additions & 55 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,80 @@ module github.com/kubevela/prism
go 1.19

require (
github.com/oam-dev/cluster-gateway v1.4.0
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/spf13/cobra v1.4.0
cuelang.org/go v0.5.0-alpha.1
github.com/emicklei/go-restful/v3 v3.8.0
github.com/oam-dev/cluster-gateway v1.6.1-0.20221118035852-bdcfca34abdb
github.com/onsi/ginkgo/v2 v2.1.6
github.com/onsi/gomega v1.20.1
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
k8s.io/apiserver v0.23.6
k8s.io/client-go v0.23.6
k8s.io/klog/v2 v2.60.1
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
github.com/stretchr/testify v1.8.0
golang.org/x/exp v0.0.0-20221114191408-850992195362
k8s.io/api v0.25.3
k8s.io/apimachinery v0.25.3
k8s.io/apiserver v0.25.3
k8s.io/client-go v0.25.3
k8s.io/klog/v2 v2.70.1
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
open-cluster-management.io/api v0.7.0
sigs.k8s.io/apiserver-runtime v1.1.1
sigs.k8s.io/apiserver-runtime v1.1.2-0.20221102045245-fb656940062f
sigs.k8s.io/controller-runtime v0.11.2
sigs.k8s.io/controller-tools v0.6.2
sigs.k8s.io/controller-tools v0.9.2
)

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/zapr v1.2.3 // 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/gobuffalo/flect v0.2.3 // indirect
github.com/gobuffalo/flect v0.2.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/openshift/library-go v0.0.0-20220112153822-ac82336bd076 // indirect
github.com/openshift/library-go v0.0.0-20221111030555-73ed40c0a938 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/v3 v3.5.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
go.opentelemetry.io/contrib v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0 // indirect
Expand All @@ -87,34 +91,35 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
google.golang.org/grpc v1.42.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver v0.23.5 // indirect
k8s.io/component-base v0.23.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/component-base v0.25.3 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
sigs.k8s.io/apiserver-network-proxy v0.0.30 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33 // 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 sigs.k8s.io/apiserver-network-proxy/konnectivity-client => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.24

replace cloud.google.com/go => cloud.google.com/go v0.100.2
Loading

0 comments on commit 8026c15

Please sign in to comment.