operator: add basic resource define

This commit is contained in:
singchia
2024-05-09 21:37:10 +08:00
parent 9d48c232dd
commit 99cbf2ee6e
16 changed files with 64 additions and 30 deletions

View File

@@ -67,11 +67,31 @@ image-gen-api:
image-gen-swagger:
docker buildx build -t frontier-gen-swagger:${VERSION} -f images/Dockerfile.controlplane-swagger .
# push
.PHONY: push
push: push-frontier push-frontlas
.PHONY: push-frontier
push-frontier:
docker push ${REGISTRY}/frontier:${VERSION}
.PHONY: push-frontlas
push-frontlas:
docker push ${REGISTRY}/frontlas:${VERSION}
# container
.PHONY: container
container: container-frontier container-frontlas
.PHONY: container-frontier
container-frontier:
docker rm -f frontier
docker run -d --name frontier -p 2431:2431 -p 2432:2432 frontier:${VERSION} --config /usr/conf/frontier.yaml -v 1
docker run -d --name frontier -p 30011:30011 -p 30012:30012 ${REGISTRY}/frontier:${VERSION} --config /usr/conf/frontier.yaml -v 1
.PHONY: container-frontlas
container-frontlas:
docker rm -f frontlas
docker run -d --name frontlas -p 30021:30021 -p 30022:30022 frontlas:${VERSION} --config /usr/conf/frontlas.yaml -v 1
# api
.PHONY: api-frontier

View File

@@ -60,7 +60,7 @@ frontlas:
enable: false
dial:
network: tcp
addr: 127.0.0.1:30021
addr: 127.0.0.1:30022
metrics:
enable: false
interval: 0

View File

@@ -9,11 +9,11 @@ daemon:
control_plane:
listen:
network: tcp
addr: 0.0.0.0:30020
addr: 0.0.0.0:30021
frontier_plane:
listen:
network: tcp
addr: 0.0.0.0:30021
addr: 0.0.0.0:30022
expiration:
service_meta: 30
edge_meta: 30

View File

@@ -72,7 +72,7 @@ func main() {
}()
network := pflag.String("network", "tcp", "network to dial")
address := pflag.String("address", "127.0.0.1:30011", "address to dial")
frontlasAddress := pflag.String("frontlas_address", "127.0.0.1:30020", "frontlas address to dial, mutex with address")
frontlasAddress := pflag.String("frontlas_address", "127.0.0.1:30021", "frontlas address to dial, mutex with address")
frontlas := pflag.Bool("frontlas", false, "frontlas or frontier")
loglevel := pflag.String("loglevel", "info", "log level, trace debug info warn error")
serviceName := pflag.String("service", "foo", "service name")

View File

@@ -21,8 +21,8 @@ RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/s
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-2.34-r0.apk
RUN apk add glibc-2.34-r0.apk
EXPOSE 30020
EXPOSE 30021
EXPOSE 30022
ENTRYPOINT ["/usr/bin/frontlas"]
CMD ["--config", "/usr/conf/frontlas.yaml"]

View File

@@ -418,7 +418,7 @@ func genDefaultConfig(writer io.Writer) error {
Enable: false,
Dial: config.Dial{
Network: "tcp",
Addr: "127.0.0.1:30021",
Addr: "127.0.0.1:30022",
TLS: config.TLS{
Enable: false,
MTLS: false,

View File

@@ -206,13 +206,13 @@ func genDefaultConfig(writer io.Writer) error {
ControlPlane: ControlPlane{
Listen: config.Listen{
Network: "tcp",
Addr: "0.0.0.0:30020",
Addr: "0.0.0.0:30021",
},
},
FrontierManager: FrontierManager{
Listen: config.Listen{
Network: "tcp",
Addr: "0.0.0.0:30021",
Addr: "0.0.0.0:30022",
},
},
Redis: Redis{

View File

@@ -28,15 +28,16 @@ type FrontierClusterSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Foo is an example field of FrontierCluster. Edit frontiercluster_types.go to remove/update
Replica string `json:"replica"`
Frontiers int `json:"frontiers"`
Frontlases int `json:"frontlases"`
}
// FrontierClusterStatus defines the observed state of FrontierCluster
type FrontierClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Replica int `json:"replica"`
CurrentFrontiers int `json:"current_frontier"`
CurrentFrontlases int `json:"current_frontlases"`
}
//+kubebuilder:object:root=true
@@ -47,8 +48,8 @@ type FrontierCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec FrontierClusterSpec `json:"spec,omitempty"`
//Status FrontierClusterStatus `json:"status,omitempty"`
Spec FrontierClusterSpec `json:"spec,omitempty"`
Status FrontierClusterStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true

View File

@@ -30,6 +30,7 @@ func (in *FrontierCluster) DeepCopyInto(out *FrontierCluster) {
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
out.Status = in.Status
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrontierCluster.

View File

@@ -34,8 +34,8 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
frontierv1alpha1 "github.com/singchia/frontier/api/v1alpha1"
"github.com/singchia/frontier/internal/controller"
frontierv1alpha1 "github.com/singchia/frontier/operator/api/v1alpha1"
"github.com/singchia/frontier/operator/internal/controller"
//+kubebuilder:scaffold:imports
)

View File

@@ -39,12 +39,27 @@ spec:
spec:
description: FrontierClusterSpec defines the desired state of FrontierCluster
properties:
replica:
description: Foo is an example field of FrontierCluster. Edit frontiercluster_types.go
to remove/update
type: string
frontiers:
type: integer
frontlases:
type: integer
required:
- replica
- frontiers
- frontlases
type: object
status:
description: FrontierClusterStatus defines the observed state of FrontierCluster
properties:
current_frontier:
description: |-
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Important: Run "make" to regenerate code after modifying this file
type: integer
current_frontlases:
type: integer
required:
- current_frontier
- current_frontlases
type: object
type: object
served: true

View File

@@ -1,4 +1,4 @@
module github.com/singchia/frontier
module github.com/singchia/frontier/operator
go 1.21

View File

@@ -18,14 +18,13 @@ package controller
import (
"context"
"encoding/json"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
frontierv1alpha1 "github.com/singchia/frontier/api/v1alpha1"
frontierv1alpha1 "github.com/singchia/frontier/operator/api/v1alpha1"
)
// FrontierClusterReconciler reconciles a FrontierCluster object
@@ -55,9 +54,7 @@ func (r *FrontierClusterReconciler) Reconcile(ctx context.Context, req ctrl.Requ
log.Error(err, "get frontier cluster error")
return ctrl.Result{}, err
}
data, _ := json.Marshal(frontiercluster)
log.Info("singchia watching", "frontiercluster", string(data))
//frontiercluster.Status.Replica = 1
if err := r.Status().Update(ctx, frontiercluster); err != nil {
log.Error(err, "unable to update status")
return ctrl.Result{}, err

View File

@@ -27,7 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
frontierv1alpha1 "github.com/singchia/frontier/api/v1alpha1"
frontierv1alpha1 "github.com/singchia/frontier/operator/api/v1alpha1"
)
var _ = Describe("FrontierCluster Controller", func() {

View File

@@ -32,7 +32,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
frontierv1alpha1 "github.com/singchia/frontier/api/v1alpha1"
frontierv1alpha1 "github.com/singchia/frontier/operator/api/v1alpha1"
//+kubebuilder:scaffold:imports
)

View File

@@ -24,7 +24,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/singchia/frontier/test/utils"
"github.com/singchia/frontier/operator/test/utils"
)
const namespace = "frontier-system"