Skip to content

Commit d93f4cd

Browse files
authored
Node agent mvp initial implementation (#65)
* node agent initial implementation * pass NodeIdentifier in fornaxcore grpc GetMessage method * a lots of node agent changes after integtest with fornaxcore * create a integtest fornaxcore grpc server * cleanup pods from store when it's terminated * remove not used ContainerStore, run test in all target
1 parent fc9a43a commit d93f4cd

File tree

162 files changed

+20389
-1493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+20389
-1493
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SHELL = /usr/bin/env bash -o pipefail
1717
.SHELLFLAGS = -ec
1818

1919
.PHONY: all
20-
all: build
20+
all: build test
2121

2222
##@ General
2323

@@ -40,11 +40,11 @@ help: ## Display this help.
4040

4141
.PHONY: manifests
4242
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
43-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/..." output:crd:artifacts:config=config/crd/bases
43+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/apis/..." output:crd:artifacts:config=config/crd/bases
4444

4545
.PHONY: generate
4646
generate: controller-gen openapi-gen client-gen ## generate-client-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
47-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/..."
47+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/core/..."
4848
# $(OPENAPI_GEN) --go-header-file="hack/boilerplate.go.txt" --input-dirs="./pkg/apis/core/..." --output-package="centaurusinfra.io/fornax-serverless/pkg/apis/openapi"
4949

5050
GENERATE_GROUPS = $(shell pwd)/hack/generate-groups.sh
@@ -71,6 +71,7 @@ test: manifests generate fmt vet envtest ## Run tests.
7171
build: generate fmt vet ## Build binary.
7272
go build ./...
7373
go build -o bin/apiserver cmd/apiserver/main.go
74+
go build -o bin/nodeagent cmd/nodeagent/main.go
7475

7576
.PHONY: run
7677
run: manifests generate fmt vet ## Run from your host.
@@ -155,6 +156,7 @@ protoc-gen: ## Download protc-gen locally if necessary.
155156
$(call go-get-tool,$(PROTOC_GEN),google.golang.org/protobuf/cmd/[email protected])
156157
$(call go-get-tool,$(PROTOC_GEN_GRPC),google.golang.org/grpc/cmd/[email protected])
157158
$(call get-protoc,$(PROTOC))
159+
go mod vendor
158160
$(PROTOC) -I=./ -I=./vendor \
159161
--go_out=../.. \
160162
--go-grpc_out=../../ \

cmd/apiserver/app/grpc_server.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package app
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"net"
23+
"time"
24+
25+
fornaxcore_grpc "centaurusinfra.io/fornax-serverless/pkg/fornaxcore/grpc"
26+
"centaurusinfra.io/fornax-serverless/pkg/fornaxcore/grpc/server"
27+
"centaurusinfra.io/fornax-serverless/pkg/fornaxcore/nodemonitor"
28+
"centaurusinfra.io/fornax-serverless/pkg/fornaxcore/podmonitor"
29+
"google.golang.org/grpc"
30+
"google.golang.org/grpc/credentials"
31+
"k8s.io/klog/v2"
32+
)
33+
34+
func RunGrpcServer(ctx context.Context, port int, certFile, keyFile string) error {
35+
36+
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
37+
if err != nil {
38+
klog.ErrorS(err, "Fornaxcore grpc server failed to listen on port:", port)
39+
return err
40+
}
41+
var opts []grpc.ServerOption
42+
if certFile != "" && keyFile != "" {
43+
creds, err := credentials.NewServerTLSFromFile(certFile, keyFile)
44+
if err != nil {
45+
klog.ErrorS(err, "Fornaxcore grpc server failed to generate credentials", "certFile", certFile, "keyFile", keyFile)
46+
return err
47+
}
48+
opts = []grpc.ServerOption{grpc.Creds(creds)}
49+
} else {
50+
51+
}
52+
53+
nodeMonitor := nodemonitor.New(10 * time.Second)
54+
podMonitor := podmonitor.New(10 * time.Second)
55+
server := server.New(nodeMonitor, podMonitor, nil)
56+
grpcServer := grpc.NewServer(opts...)
57+
fornaxcore_grpc.RegisterFornaxCoreServiceServer(grpcServer, server)
58+
go func() {
59+
err = grpcServer.Serve(lis)
60+
if err != nil {
61+
klog.ErrorS(err, "Fornaxcore grpc server stopped to serve")
62+
}
63+
}()
64+
65+
return nil
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package app
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"net"
23+
"time"
24+
25+
fornaxcore_grpc "centaurusinfra.io/fornax-serverless/pkg/fornaxcore/grpc"
26+
"centaurusinfra.io/fornax-serverless/pkg/fornaxcore/grpc/server"
27+
"centaurusinfra.io/fornax-serverless/pkg/fornaxcore/nodemonitor"
28+
"centaurusinfra.io/fornax-serverless/pkg/fornaxcore/podmonitor"
29+
"google.golang.org/grpc"
30+
"google.golang.org/grpc/credentials"
31+
"k8s.io/klog/v2"
32+
)
33+
34+
func RunIntegTestGrpcServer(ctx context.Context, port int, certFile, keyFile string) error {
35+
36+
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
37+
if err != nil {
38+
klog.ErrorS(err, "Fornaxcore grpc server failed to listen on port:", port)
39+
return err
40+
}
41+
var opts []grpc.ServerOption
42+
if certFile != "" && keyFile != "" {
43+
creds, err := credentials.NewServerTLSFromFile(certFile, keyFile)
44+
if err != nil {
45+
klog.ErrorS(err, "Fornaxcore grpc server failed to generate credentials", "certFile", certFile, "keyFile", keyFile)
46+
return err
47+
}
48+
opts = []grpc.ServerOption{grpc.Creds(creds)}
49+
} else {
50+
51+
}
52+
53+
nodeMonitor := nodemonitor.NewIntegNodeMonitor(10 * time.Second)
54+
podMonitor := podmonitor.NewIntegPodMonitor(10 * time.Second)
55+
server := server.New(nodeMonitor, podMonitor, nil)
56+
grpcServer := grpc.NewServer(opts...)
57+
fornaxcore_grpc.RegisterFornaxCoreServiceServer(grpcServer, server)
58+
go func() {
59+
err = grpcServer.Serve(lis)
60+
if err != nil {
61+
klog.ErrorS(err, "Fornaxcore grpc server stopped to serve")
62+
}
63+
}()
64+
65+
return nil
66+
}

cmd/apiserver/main.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -28,6 +29,7 @@ import (
2829
"sigs.k8s.io/apiserver-runtime/pkg/builder"
2930

3031
// +kubebuilder:scaffold:resource-imports
32+
"centaurusinfra.io/fornax-serverless/cmd/apiserver/app"
3133
fornaxv1 "centaurusinfra.io/fornax-serverless/pkg/apis/core/v1"
3234
)
3335

@@ -52,7 +54,21 @@ func main() {
5254
}
5355
}
5456

55-
err := builder.APIServer.
57+
// start fornaxcore grpc server
58+
klog.Info("starting fornaxcore grpc server")
59+
port := 18001
60+
certFile := ""
61+
keyFile := ""
62+
// err := app.RunGrpcServer(context.Background(), port, certFile, keyFile)
63+
err := app.RunIntegTestGrpcServer(context.Background(), port, certFile, keyFile)
64+
if err != nil {
65+
klog.Fatal(err)
66+
}
67+
klog.Info("Fornaxcore grpc server started")
68+
69+
klog.Info("starting fornaxcore k8s.io rest api server")
70+
// +kubebuilder:scaffold:resource-register
71+
apiserver := builder.APIServer.
5672
WithLocalDebugExtension().
5773
WithResourceAndStorage(&fornaxv1.Application{}, storageFunc).
5874
WithResourceAndStorage(&fornaxv1.ApplicationInstance{}, storageFunc).
@@ -63,9 +79,38 @@ func main() {
6379
fmt.Printf("%T\n", config.Authentication.Authenticator)
6480
fmt.Println(config.Authentication.APIAudiences)
6581
return config
66-
}).
67-
Execute()
82+
})
83+
84+
// WithResource(&v1.Pod{}).
85+
// WithResource(&k8scorev1.FornaxNode{}).
86+
// WithResource(&k8scorev1.FornaxSecret{}).
87+
// WithResource(&k8scorev1.FornaxConfigMap{}).
88+
// WithResource(&k8scorev1.FornaxServiceAccount{}).
89+
// WithFlagFns(fns ...func(set *pflag.FlagSet) *pflag.FlagSet).
90+
// // Authentication is the configuration for authentication
91+
// Authentication AuthenticationInfo
92+
//
93+
// // Authorization is the configuration for authorization
94+
// Authorization AuthorizationInfo
95+
96+
// LoopbackClientConfig is a config for a privileged loopback connection to the API server
97+
// This is required for proper functioning of the PostStartHooks on a GenericAPIServer
98+
// TODO: move into SecureServing(WithLoopback) as soon as insecure serving is gone
99+
// LoopbackClientConfig * restclient.Config
100+
101+
// EgressSelector provides a lookup mechanism for dialing outbound connections.
102+
// It does so based on a EgressSelectorConfiguration which was read at startup.
103+
// EgressSelector * egressselector.EgressSelector
104+
105+
// WithServerFns(func(server *builder.GenericAPIServer) *builder.GenericAPIServer {
106+
// apiGroupInfo := *apiserver.APIGroupInfo{}
107+
// server.InstallLegacyAPIGroup(apiserver.DefaultLegacyAPIPrefix, apiGroupInfo)
108+
// return server
109+
// }).
110+
111+
err = apiserver.Execute()
68112
if err != nil {
69113
klog.Fatal(err)
70114
}
115+
71116
}

0 commit comments

Comments
 (0)