Skip to content

Commit 00f4b0a

Browse files
author
yumaojun03
committed
update operator
1 parent 70c17c1 commit 00f4b0a

File tree

7 files changed

+459
-117
lines changed

7 files changed

+459
-117
lines changed

cmd/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
devopsv1beta1 "github.com/infraboard/devops/moperator/api/v1beta1"
3939
"github.com/infraboard/devops/moperator/internal/controller"
40+
"github.com/infraboard/mcube/v2/ioc"
4041
// +kubebuilder:scaffold:imports
4142
)
4243

@@ -61,6 +62,7 @@ func main() {
6162
var probeAddr string
6263
var secureMetrics bool
6364
var enableHTTP2 bool
65+
var configPath string
6466
var tlsOpts []func(*tls.Config)
6567
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
6668
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
@@ -77,6 +79,7 @@ func main() {
7779
"The directory that contains the metrics server certificate.")
7880
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
7981
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
82+
flag.StringVar(&configPath, "config-path", "etc/application.toml", "The path to the configuration file.")
8083
flag.BoolVar(&enableHTTP2, "enable-http2", false,
8184
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
8285
opts := zap.Options{
@@ -87,6 +90,9 @@ func main() {
8790

8891
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
8992

93+
// 开启配置文件读取配置
94+
ioc.DevelopmentSetupWithPath(configPath)
95+
9096
// if the enable-http2 flag is false (the default), http/2 should be disabled
9197
// due to its vulnerabilities. More specifically, disabling http/2 will
9298
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
@@ -178,11 +184,11 @@ func main() {
178184
os.Exit(1)
179185
}
180186

181-
if err := (&controller.McloudReconciler{
187+
if err := (&controller.DeploymentReconciler{
182188
Client: mgr.GetClient(),
183189
Scheme: mgr.GetScheme(),
184190
}).SetupWithManager(mgr); err != nil {
185-
setupLog.Error(err, "unable to create controller", "controller", "Mcloud")
191+
setupLog.Error(err, "unable to create controller", "controller", "Deployment")
186192
os.Exit(1)
187193
}
188194
// +kubebuilder:scaffold:builder
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.18.0
7+
name: mclouds.devops.devops.mcloud
8+
spec:
9+
group: devops.devops.mcloud
10+
names:
11+
kind: Mcloud
12+
listKind: McloudList
13+
plural: mclouds
14+
singular: mcloud
15+
scope: Namespaced
16+
versions:
17+
- name: v1beta1
18+
schema:
19+
openAPIV3Schema:
20+
description: Mcloud is the Schema for the mclouds API
21+
properties:
22+
apiVersion:
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
28+
type: string
29+
kind:
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
description: spec defines the desired state of Mcloud
41+
properties:
42+
foo:
43+
description: foo is an example field of Mcloud. Edit mcloud_types.go
44+
to remove/update
45+
type: string
46+
type: object
47+
status:
48+
description: status defines the observed state of Mcloud
49+
properties:
50+
conditions:
51+
description: |-
52+
conditions represent the current state of the Mcloud resource.
53+
Each condition has a unique type and reflects the status of a specific aspect of the resource.
54+
55+
Standard condition types include:
56+
- "Available": the resource is fully functional
57+
- "Progressing": the resource is being created or updated
58+
- "Degraded": the resource failed to reach or maintain its desired state
59+
60+
The status of each condition is one of True, False, or Unknown.
61+
items:
62+
description: Condition contains details for one aspect of the current
63+
state of this API Resource.
64+
properties:
65+
lastTransitionTime:
66+
description: |-
67+
lastTransitionTime is the last time the condition transitioned from one status to another.
68+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
69+
format: date-time
70+
type: string
71+
message:
72+
description: |-
73+
message is a human readable message indicating details about the transition.
74+
This may be an empty string.
75+
maxLength: 32768
76+
type: string
77+
observedGeneration:
78+
description: |-
79+
observedGeneration represents the .metadata.generation that the condition was set based upon.
80+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
81+
with respect to the current state of the instance.
82+
format: int64
83+
minimum: 0
84+
type: integer
85+
reason:
86+
description: |-
87+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
88+
Producers of specific condition types may define expected values and meanings for this field,
89+
and whether the values are considered a guaranteed API.
90+
The value should be a CamelCase string.
91+
This field may not be empty.
92+
maxLength: 1024
93+
minLength: 1
94+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
95+
type: string
96+
status:
97+
description: status of the condition, one of True, False, Unknown.
98+
enum:
99+
- "True"
100+
- "False"
101+
- Unknown
102+
type: string
103+
type:
104+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
105+
maxLength: 316
106+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
107+
type: string
108+
required:
109+
- lastTransitionTime
110+
- message
111+
- reason
112+
- status
113+
- type
114+
type: object
115+
type: array
116+
x-kubernetes-list-map-keys:
117+
- type
118+
x-kubernetes-list-type: map
119+
type: object
120+
required:
121+
- spec
122+
type: object
123+
served: true
124+
storage: true
125+
subresources:
126+
status: {}

config/rbac/role.yaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
---
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRole
34
metadata:
4-
labels:
5-
app.kubernetes.io/name: moperator
6-
app.kubernetes.io/managed-by: kustomize
75
name: manager-role
86
rules:
9-
- apiGroups: [""]
10-
resources: ["pods"]
11-
verbs: ["get", "list", "watch"]
7+
- apiGroups:
8+
- devops.devops.mcloud
9+
resources:
10+
- mclouds
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- devops.devops.mcloud
21+
resources:
22+
- mclouds/finalizers
23+
verbs:
24+
- update
25+
- apiGroups:
26+
- devops.devops.mcloud
27+
resources:
28+
- mclouds/status
29+
verbs:
30+
- get
31+
- patch
32+
- update

etc/application.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[app]
2+
name = "moperator"
3+
description = "app desc"
4+
5+
[devops_client]
6+
address = "http://127.0.0.1:9090/jsonrpc/devcloud/v1"

go.mod

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module github.com/infraboard/devops/moperator
33
go 1.24.5
44

55
require (
6+
github.com/infraboard/devops v0.0.8
7+
github.com/infraboard/mcube/v2 v2.0.83
68
github.com/onsi/ginkgo/v2 v2.22.0
79
github.com/onsi/gomega v1.36.1
810
k8s.io/api v0.33.0
@@ -12,24 +14,32 @@ require (
1214
)
1315

1416
require (
15-
cel.dev/expr v0.19.1 // indirect
17+
cel.dev/expr v0.24.0 // indirect
18+
filippo.io/edwards25519 v1.1.0 // indirect
19+
github.com/BurntSushi/toml v1.5.0 // indirect
1620
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
1721
github.com/beorn7/perks v1.0.1 // indirect
1822
github.com/blang/semver/v4 v4.0.0 // indirect
19-
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
23+
github.com/caarlos0/env/v6 v6.10.1 // indirect
24+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
2025
github.com/cespare/xxhash/v2 v2.3.0 // indirect
21-
github.com/davecgh/go-spew v1.1.1 // indirect
22-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
26+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
27+
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
2328
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
2429
github.com/felixge/httpsnoop v1.0.4 // indirect
2530
github.com/fsnotify/fsnotify v1.7.0 // indirect
2631
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
27-
github.com/go-logr/logr v1.4.2 // indirect
32+
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
33+
github.com/go-logr/logr v1.4.3 // indirect
2834
github.com/go-logr/stdr v1.2.2 // indirect
2935
github.com/go-logr/zapr v1.3.0 // indirect
3036
github.com/go-openapi/jsonpointer v0.21.0 // indirect
31-
github.com/go-openapi/jsonreference v0.20.2 // indirect
37+
github.com/go-openapi/jsonreference v0.21.0 // indirect
3238
github.com/go-openapi/swag v0.23.0 // indirect
39+
github.com/go-playground/locales v0.14.1 // indirect
40+
github.com/go-playground/universal-translator v0.18.1 // indirect
41+
github.com/go-playground/validator/v10 v10.26.0 // indirect
42+
github.com/go-sql-driver/mysql v1.8.1 // indirect
3343
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
3444
github.com/gogo/protobuf v1.3.2 // indirect
3545
github.com/google/btree v1.1.3 // indirect
@@ -38,60 +48,83 @@ require (
3848
github.com/google/go-cmp v0.7.0 // indirect
3949
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
4050
github.com/google/uuid v1.6.0 // indirect
41-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
51+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
52+
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
53+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
4254
github.com/inconshreveable/mousetrap v1.1.0 // indirect
55+
github.com/infraboard/modules v0.0.22 // indirect
56+
github.com/jinzhu/inflection v1.0.0 // indirect
57+
github.com/jinzhu/now v1.1.5 // indirect
4358
github.com/josharian/intern v1.0.0 // indirect
4459
github.com/json-iterator/go v1.1.12 // indirect
60+
github.com/leodido/go-urn v1.4.0 // indirect
4561
github.com/mailru/easyjson v0.7.7 // indirect
62+
github.com/mattn/go-colorable v0.1.13 // indirect
63+
github.com/mattn/go-isatty v0.0.20 // indirect
64+
github.com/mitchellh/mapstructure v1.5.0 // indirect
65+
github.com/moby/spdystream v0.5.0 // indirect
4666
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4767
github.com/modern-go/reflect2 v1.0.2 // indirect
4868
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
69+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
4970
github.com/pkg/errors v0.9.1 // indirect
50-
github.com/prometheus/client_golang v1.22.0 // indirect
51-
github.com/prometheus/client_model v0.6.1 // indirect
52-
github.com/prometheus/common v0.62.0 // indirect
53-
github.com/prometheus/procfs v0.15.1 // indirect
54-
github.com/spf13/cobra v1.8.1 // indirect
55-
github.com/spf13/pflag v1.0.5 // indirect
71+
github.com/prometheus/client_golang v1.23.1 // indirect
72+
github.com/prometheus/client_model v0.6.2 // indirect
73+
github.com/prometheus/common v0.66.0 // indirect
74+
github.com/prometheus/procfs v0.16.1 // indirect
75+
github.com/rs/zerolog v1.34.0 // indirect
76+
github.com/spf13/cobra v1.10.1 // indirect
77+
github.com/spf13/pflag v1.0.9 // indirect
5678
github.com/stoewer/go-strcase v1.3.0 // indirect
5779
github.com/x448/float16 v0.8.4 // indirect
5880
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
59-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
60-
go.opentelemetry.io/otel v1.33.0 // indirect
61-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
62-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect
63-
go.opentelemetry.io/otel/metric v1.33.0 // indirect
64-
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
65-
go.opentelemetry.io/otel/trace v1.33.0 // indirect
66-
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
81+
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.62.0 // indirect
82+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
83+
go.opentelemetry.io/otel v1.38.0 // indirect
84+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
85+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0 // indirect
86+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0 // indirect
87+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
88+
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
89+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
90+
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
6791
go.uber.org/multierr v1.11.0 // indirect
6892
go.uber.org/zap v1.27.0 // indirect
93+
go.yaml.in/yaml/v2 v2.4.2 // indirect
94+
golang.org/x/crypto v0.41.0 // indirect
6995
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
70-
golang.org/x/net v0.38.0 // indirect
71-
golang.org/x/oauth2 v0.27.0 // indirect
72-
golang.org/x/sync v0.12.0 // indirect
73-
golang.org/x/sys v0.31.0 // indirect
74-
golang.org/x/term v0.30.0 // indirect
75-
golang.org/x/text v0.23.0 // indirect
96+
golang.org/x/net v0.43.0 // indirect
97+
golang.org/x/oauth2 v0.30.0 // indirect
98+
golang.org/x/sync v0.16.0 // indirect
99+
golang.org/x/sys v0.35.0 // indirect
100+
golang.org/x/term v0.34.0 // indirect
101+
golang.org/x/text v0.28.0 // indirect
76102
golang.org/x/time v0.9.0 // indirect
77-
golang.org/x/tools v0.26.0 // indirect
103+
golang.org/x/tools v0.35.0 // indirect
78104
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
79-
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
80-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
81-
google.golang.org/grpc v1.68.1 // indirect
82-
google.golang.org/protobuf v1.36.5 // indirect
105+
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
106+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
107+
google.golang.org/grpc v1.75.0 // indirect
108+
google.golang.org/protobuf v1.36.8 // indirect
83109
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
84110
gopkg.in/inf.v0 v0.9.1 // indirect
111+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
112+
gopkg.in/yaml.v2 v2.4.0 // indirect
85113
gopkg.in/yaml.v3 v3.0.1 // indirect
114+
gorm.io/datatypes v1.2.5 // indirect
115+
gorm.io/driver/mysql v1.6.0 // indirect
116+
gorm.io/gorm v1.30.3 // indirect
86117
k8s.io/apiextensions-apiserver v0.33.0 // indirect
87118
k8s.io/apiserver v0.33.0 // indirect
88119
k8s.io/component-base v0.33.0 // indirect
89120
k8s.io/klog/v2 v2.130.1 // indirect
90121
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
122+
k8s.io/kubectl v0.33.0 // indirect
91123
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
124+
resty.dev/v3 v3.0.0-beta.3 // indirect
92125
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
93126
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
94127
sigs.k8s.io/randfill v1.0.0 // indirect
95128
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
96-
sigs.k8s.io/yaml v1.4.0 // indirect
129+
sigs.k8s.io/yaml v1.6.0 // indirect
97130
)

0 commit comments

Comments
 (0)