Skip to content

Commit

Permalink
Introduce main for runtime-manager (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: honpey <honpey@gmail.com>
  • Loading branch information
honpey authored May 26, 2022
1 parent ea8496c commit 093647a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
make vet && git add pkg cmd &&
git diff --cached --exit-code || (echo 'Please run "make vet" to verify govet' && exit 1);
- name: Run Go build
run: make build-koordlet build-koord-manager build-koord-scheduler
run: make build-koordlet build-koord-manager build-koord-scheduler build-runtime-manager
- name: Run Go test
run: make test
- name: Upload coverage to Codecov
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test: manifests generate fmt vet envtest ## Run tests.
##@ Build

.PHONY: build
build: generate fmt vet lint build-koordlet build-koord-manager build-koord-scheduler
build: generate fmt vet lint build-koordlet build-koord-manager build-koord-scheduler build-runtime-manager

.PHONY: build-koordlet
build-koordlet: ## Build koordlet binary.
Expand All @@ -104,6 +104,10 @@ build-koord-manager: ## Build koord-manager binary.
build-koord-scheduler: ## Build koord-scheduler binary.
go build -o bin/koord-scheduler cmd/koord-scheduler/main.go

.PHONY: build-runtime-manager
build-runtime-manager: ## Build runtime-manager binary.
go build -o bin/runtime-manager cmd/runtime-manager/main.go

.PHONY: docker-build
docker-build: test docker-build-koordlet docker-build-koord-manager docker-build-koord-scheduler

Expand Down
55 changes: 55 additions & 0 deletions cmd/runtime-manager/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"flag"

"github.com/spf13/pflag"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordinator/cmd/runtime-manager/options"
"github.com/koordinator-sh/koordinator/pkg/runtime-manager/server/cri"
)

func main() {
flag.StringVar(&options.RuntimeManagerEndpoint, "runtime-manager-endpoint", options.DefaultRuntimeManagerEndpoint,
"runtime-manager service endpoint.")
flag.StringVar(&options.RemoteRuntimeServiceEndpoint, "remote-runtime-service-endpoint", options.DefaultContainerdRuntimeServiceEndpoint,
"backend runtime service endpoint.")
flag.StringVar(&options.RemoteImageServiceEndpoint, "remote-image-service-endpoint", options.DefaultContainerdImageServiceEndpoint,
"backend image service endpoint.")
flag.StringVar(&options.BackendRuntimeMode, "backend-runtime-mode", options.DefaultBackendRuntimeMode,
"backend container engine(Containerd|Docker).")

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

switch options.BackendRuntimeMode {
case options.BackendRuntimeModeContainerd:
server := cri.NewRuntimeManagerCriServer()
go server.Run()
case options.BackendRuntimeModeDocker:
default:
klog.Fatalf("unknown runtime engine backend %v", options.BackendRuntimeMode)
}

stopCh := genericapiserver.SetupSignalHandler()
<-stopCh
klog.Info("RuntimeManager shutting down")
}
37 changes: 37 additions & 0 deletions cmd/runtime-manager/options/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

const (
DefaultRuntimeManagerEndpoint = "/var/run/runtime-manager/runtimemanager.sock"

DefaultContainerdRuntimeServiceEndpoint = "/var/run/containerd/containerd.sock"
DefaultContainerdImageServiceEndpoint = "/var/run/containerd/containerd.sock"

BackendRuntimeModeContainerd = "Containerd"
BackendRuntimeModeDocker = "Docker"
DefaultBackendRuntimeMode = BackendRuntimeModeContainerd
)

var (
RuntimeManagerEndpoint string
RemoteRuntimeServiceEndpoint string
RemoteImageServiceEndpoint string

// BackendRuntimeMode default to 'containerd'
BackendRuntimeMode string
)
21 changes: 14 additions & 7 deletions pkg/runtime-manager/server/cri/criserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ import (
"context"
"net"
"os"
"path/filepath"
"time"

"google.golang.org/grpc"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordinator/cmd/runtime-manager/options"
"github.com/koordinator-sh/koordinator/pkg/runtime-manager/config"
"github.com/koordinator-sh/koordinator/pkg/runtime-manager/dispatcher"
resource_executor "github.com/koordinator-sh/koordinator/pkg/runtime-manager/resource-executor"
cri_resource_executor "github.com/koordinator-sh/koordinator/pkg/runtime-manager/resource-executor/cri"
"github.com/koordinator-sh/koordinator/pkg/runtime-manager/server/utils"
)

const (
Expand All @@ -43,9 +44,9 @@ type RuntimeManagerCriServer struct {
backendImageServiceClient runtimeapi.ImageServiceClient
}

func NewRuntimeManagerCriServer(dispatcher *dispatcher.RuntimeHookDispatcher) *RuntimeManagerCriServer {
func NewRuntimeManagerCriServer() *RuntimeManagerCriServer {
criInterceptor := &RuntimeManagerCriServer{
hookDispatcher: dispatcher,
hookDispatcher: dispatcher.NewRuntimeDispatcher(),
}
return criInterceptor
}
Expand All @@ -55,18 +56,24 @@ func (c *RuntimeManagerCriServer) Name() string {
}

func (c *RuntimeManagerCriServer) Run() error {
if err := c.initBackendServer(utils.DefaultRuntimeServiceSocketPath, utils.DefaultImageServiceSocketPath); err != nil {
if err := c.initBackendServer(options.RemoteRuntimeServiceEndpoint, options.RemoteImageServiceEndpoint); err != nil {
return err
}
c.failOver()

klog.Infof("do failOver done")

if err := os.Remove(utils.DefaultRuntimeManagerSocketPath); err != nil && os.IsNotExist(err) {
klog.Errorf("fail to unlink %v: %v", utils.DefaultRuntimeManagerSocketPath, err)
if err := os.Remove(options.RuntimeManagerEndpoint); err != nil && !os.IsNotExist(err) {
klog.Errorf("fail to unlink %v: %v", options.RuntimeManagerEndpoint, err)
return err
}

if err := os.MkdirAll(filepath.Dir(options.RuntimeManagerEndpoint), 0755); err != nil {
klog.Errorf("fail to mkdir %v: %v", filepath.Base(options.RuntimeManagerEndpoint), err)
return err
}

lis, err := net.Listen("unix", utils.DefaultRuntimeManagerSocketPath)
lis, err := net.Listen("unix", options.RuntimeManagerEndpoint)
if err != nil {
klog.Errorf("fail to create the lis %v", err)
return err
Expand Down
25 changes: 0 additions & 25 deletions pkg/runtime-manager/server/utils/utils.go

This file was deleted.

0 comments on commit 093647a

Please sign in to comment.