Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhoublue committed Feb 18, 2024
1 parent 6789740 commit 4888691
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 264 deletions.
10 changes: 5 additions & 5 deletions charts/crds/rocktemplate.spidernet.io_mybooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: (unknown)
creationTimestamp: null
name: mybooks.koffloader.koffloader.io
name: kclusters.koffloader.koffloader.io
spec:
group: koffloader.koffloader.io
names:
categories:
- koffloader
kind: Mybook
listKind: MybookList
plural: mybooks
kind: Kcluster
listKind: KclusterList
plural: kclusters
shortNames:
- mb
singular: mybook
singular: kcluster
scope: Cluster
versions:
- additionalPrinterColumns:
Expand Down
4 changes: 2 additions & 2 deletions charts/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ rules:
- apiGroups:
- koffloader.koffloader.io
resources:
- mybooks
- kclusters
verbs:
- create
- delete
Expand All @@ -73,7 +73,7 @@ rules:
- apiGroups:
- koffloader.koffloader.io
resources:
- mybooks/status
- kclusters/status
verbs:
- get
- patch
Expand Down
12 changes: 6 additions & 6 deletions charts/templates/tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ webhooks:
name: {{ .Values.koffloaderController.name | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
# ====modify==== the mutating route path : "/mutate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind)
path: "/mutate-koffloader-koffloader-io-v1-mybook"
path: "/mutate-koffloader-koffloader-io-v1-kcluster"
port: {{ .Values.koffloaderController.webhookPort }}
{{- if (eq .Values.koffloaderController.tls.method "provided") }}
caBundle: {{ .Values.koffloaderController.tls.provided.tlsCa | required "missing tls.provided.tlsCa" }}
Expand All @@ -27,7 +27,7 @@ webhooks:
{{- end }}
failurePolicy: Fail
# ====modify====
name: mybook.koffloader.koffloader.io
name: kcluster.koffloader.koffloader.io
rules:
- apiGroups:
# ====modify====
Expand All @@ -40,7 +40,7 @@ webhooks:
- DELETE
resources:
# ====modify==== crdName
- mybooks
- kclusters
sideEffects: None

---
Expand All @@ -60,7 +60,7 @@ webhooks:
name: {{ .Values.koffloaderController.name | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
# ====modify==== the validate route path : "/validate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind)
path: "/validate-koffloader-koffloader-io-v1-mybook"
path: "/validate-koffloader-koffloader-io-v1-kcluster"
port: {{ .Values.koffloaderController.webhookPort }}
{{- if (eq .Values.koffloaderController.tls.method "provided") }}
caBundle: {{ .Values.koffloaderController.tls.provided.tlsCa | required "missing tls.provided.tlsCa" }}
Expand All @@ -69,7 +69,7 @@ webhooks:
{{- end }}
failurePolicy: Fail
# ====modify====
name: mybook.koffloader.koffloader.io
name: kcluster.koffloader.koffloader.io
rules:
- apiGroups:
# ====modify====
Expand All @@ -82,7 +82,7 @@ webhooks:
- DELETE
resources:
# ====modify==== crdName
- mybooks
- kclusters
sideEffects: None

{{- if eq .Values.koffloaderController.tls.method "certmanager" -}}
Expand Down
4 changes: 2 additions & 2 deletions cmd/controller/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"context"
"github.com/koffloader-io/koffloader/pkg/debug"
"github.com/koffloader-io/koffloader/pkg/mybookManager"
"github.com/koffloader-io/koffloader/pkg/kclusterManager"
"github.com/koffloader-io/koffloader/pkg/types"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
Expand Down Expand Up @@ -52,7 +52,7 @@ func DaemonMain() {
MetricHistogramDuration.Record(context.Background(), 20)

// ----------
s := mybookManager.New(rootLogger.Named("mybook"))
s := kclusterManager.New(rootLogger.Named("kcluster"))
s.RunController("testlease", types.ControllerConfig.PodNamespace, types.ControllerConfig.PodName)
s.RunWebhookServer(int(types.ControllerConfig.WebhookPort), filepath.Dir(types.ControllerConfig.TlsServerCertPath))

Expand Down
18 changes: 9 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

4. redefine CRD in pkg/k8s/v1
rename directory name 'pkg/k8s/apis/koffloader.koffloader.io'
replace all 'mybook' to 'YourCRDName'
and `make update_crd_sdk`, and write code in pkg/mybookManager
replace all 'kcluster' to 'YourCRDName'
and `make update_crd_sdk`, and write code in pkg/kclusterManager

rename pkg/mybookManager and replace all 'mybook' with your CRD name in this directory
rename pkg/kclusterManager and replace all 'kcluster' with your CRD name in this directory

rm charts/crds/koffloader.koffloader.io_mybooks.yaml
rm charts/crds/koffloader.koffloader.io_kclusters.yaml

# in repo: replace all "github.com/koffloader-io/spiderdoctor/pkg/mybookManager" to "github.com/koffloader-io/spiderdoctor/pkg/${crdName}Manager"
# in repo: find and replace all "mybook" to YourCrd
# in repo: replace all "github.com/koffloader-io/spiderdoctor/pkg/kclusterManager" to "github.com/koffloader-io/spiderdoctor/pkg/${crdName}Manager"
# in repo: find and replace all "kcluster" to YourCrd

5. update charts/ , and images/ , and CODEOWNERS

Expand Down Expand Up @@ -98,16 +98,16 @@

5. apply cr

cat <<EOF > mybook.yaml
cat <<EOF > kcluster.yaml
apiVersion: koffloader.koffloader.io/v1
kind: Mybook
kind: Kcluster
metadata:
name: test
spec:
ipVersion: 4
subnet: "1.0.0.0/8"
EOF
kubectl apply -f mybook.yaml
kubectl apply -f kcluster.yaml

## chart develop

Expand Down
12 changes: 6 additions & 6 deletions docs/develop/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ helm repo add koffloader https://koffloader-io.github.io/koffloader

```shell

cat <<EOF > mybook1.yaml
cat <<EOF > kcluster1.yaml
apiVersion: koffloader.koffloader.io/v1
kind: Mybook
kind: Kcluster
metadata:
name: test1
spec:
ipVersion: 4
subnet: "1.0.0.0/8"
EOF

kubectl apply -f mybook1.yaml
kubectl apply -f kcluster1.yaml


cat <<EOF > mybook2.yaml
cat <<EOF > kcluster2.yaml
apiVersion: koffloader.koffloader.io/v1
kind: Mybook
kind: Kcluster
metadata:
name: test2
spec:
ipVersion: 4
subnet: "2.0.0.0/8"
EOF

kubectl apply -f mybook2.yaml
kubectl apply -f kcluster2.yaml


```
12 changes: 6 additions & 6 deletions docs/usage/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

```shell

cat <<EOF > mybook1.yaml
cat <<EOF > kcluster1.yaml
apiVersion: koffloader.koffloader.io/v1
kind: Mybook
kind: Kcluster
metadata:
name: test1
spec:
ipVersion: 4
subnet: "1.0.0.0/8"
EOF

kubectl apply -f mybook1.yaml
kubectl apply -f kcluster1.yaml


cat <<EOF > mybook2.yaml
cat <<EOF > kcluster2.yaml
apiVersion: koffloader.koffloader.io/v1
kind: Mybook
kind: Kcluster
metadata:
name: test2
spec:
ipVersion: 4
subnet: "2.0.0.0/8"
EOF

kubectl apply -f mybook2.yaml
kubectl apply -f kcluster2.yaml


```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type MybookSpec struct {
type KclusterSpec struct {
// +kubebuilder:validation:Enum=4;6
// +kubebuilder:validation:Optional
IPVersion *int64 `json:"ipVersion,omitempty"`
Expand All @@ -38,7 +38,7 @@ type MybookSpec struct {
NodeAffinity *metav1.LabelSelector `json:"nodeAffinity,omitempty"`
}

type MybookStatus struct {
type KclusterStatus struct {
// +kubebuilder:validation:Minimum=0
TotalIPCount int64 `json:"totalIPCount"`

Expand All @@ -49,7 +49,7 @@ type MybookStatus struct {
}

// scope(Namespaced or Cluster)
// +kubebuilder:resource:categories={koffloader},path="mybooks",singular="mybook",scope="Cluster",shortName={mb}
// +kubebuilder:resource:categories={koffloader},path="kclusters",singular="kcluster",scope="Cluster",shortName={mb}
// +kubebuilder:printcolumn:JSONPath=".spec.ipVersion",description="ipVersion",name="VERSION",type=string
// +kubebuilder:printcolumn:JSONPath=".spec.subnet",description="subnet",name="SUBNET",type=string
// +kubebuilder:printcolumn:JSONPath=".status.totalIPCount",description="totalIPCount",name="TOTAL-IP-COUNT",type=integer
Expand All @@ -58,23 +58,23 @@ type MybookStatus struct {
// +genclient
// +genclient:nonNamespaced

type Mybook struct {
type Kcluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`

Spec MybookSpec `json:"spec,omitempty"`
Status MybookStatus `json:"status,omitempty"`
Spec KclusterSpec `json:"spec,omitempty"`
Status KclusterStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

type MybookList struct {
type KclusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Mybook `json:"items"`
Items []Kcluster `json:"items"`
}

func init() {
SchemeBuilder.Register(&Mybook{}, &MybookList{})
SchemeBuilder.Register(&Kcluster{}, &KclusterList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/rbac/parser.go
// https://book.kubebuilder.io/reference/markers/rbac.html

// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=mybooks,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=mybooks/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=kclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=kclusters/status,verbs=get;update;patch

// +kubebuilder:rbac:groups="",resources=events,verbs=create;get;list;watch;update;delete
// +kubebuilder:rbac:groups="coordination.k8s.io",resources=leases,verbs=create;get;update
Expand Down
Loading

0 comments on commit 4888691

Please sign in to comment.