diff --git a/housekeeper/daemon/main.go b/housekeeper/daemon/main.go new file mode 100644 index 0000000000000000000000000000000000000000..c843375b0ee1ca947cd1d6679d2f1a0673952138 --- /dev/null +++ b/housekeeper/daemon/main.go @@ -0,0 +1,33 @@ +/* +Copyright 2023 KylinSoft Co., Ltd. + +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 ( + "os" + + "github.com/sirupsen/logrus" + "housekeeper.io/daemon/server" + "housekeeper.io/pkg/version" + _ "k8s.io/client-go/plugin/pkg/client/auth" +) + +func main() { + logrus.Info("Version is:", version.Version) + if err := server.Run(); err != nil { + logrus.Errorln("listen error" + err.Error()) + os.Exit(1) + } +} diff --git a/housekeeper/daemon/server/listener.go b/housekeeper/daemon/server/listener.go new file mode 100644 index 0000000000000000000000000000000000000000..007ef7fe9d75f38b432642fb4d88428375eaca0c --- /dev/null +++ b/housekeeper/daemon/server/listener.go @@ -0,0 +1,75 @@ +/* +Copyright 2023 KylinSoft Co., Ltd. + +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 server + +import ( + "fmt" + "net" + "os" + "path/filepath" + "syscall" + + "github.com/sirupsen/logrus" + "google.golang.org/grpc" + pb "housekeeper.io/pkg/connection/proto" + "housekeeper.io/pkg/constants" +) + +func NewListener(dir, name string) (l net.Listener, err error) { + if err := os.MkdirAll(dir, 0750); err != nil { + return nil, err + } + + addr := filepath.Join(dir, name) + gid := os.Getgid() + if err = syscall.Unlink(addr); err != nil && !os.IsNotExist(err) { + return nil, err + } + + const socketPermission = 0640 + mask := syscall.Umask(^socketPermission & int(os.ModePerm)) + defer syscall.Umask(mask) + + l, err = net.Listen("unix", addr) + if err != nil { + return nil, err + } + + if err := os.Chown(addr, 0, gid); err != nil { + if err := l.Close(); err != nil { + return nil, fmt.Errorf("close listener error %w", err) + } + return nil, err + } + return l, nil +} + +func Run() error { + lis, err := NewListener(constants.SockDir, constants.SockName) + if err != nil { + logrus.Errorf("listen error: %v", err) + return err + } + //get grpc server + s := grpc.NewServer() + pb.RegisterUpgradeClusterServer(s, &Server{}) + logrus.Info("housekeeper-daemon start serving") + if err := s.Serve(lis); err != nil { + logrus.Errorf("housekeeper-daemon server error: %v", err) + return err + } + return nil +} diff --git a/housekeeper/daemon/server/server.go b/housekeeper/daemon/server/server.go new file mode 100644 index 0000000000000000000000000000000000000000..42a5b854a3e84605d460dd7e07e84f00b14b9099 --- /dev/null +++ b/housekeeper/daemon/server/server.go @@ -0,0 +1,33 @@ +/* +Copyright 2023 KylinSoft Co., Ltd. + +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 server + +import ( + "context" + + pb "housekeeper.io/pkg/connection/proto" +) + +type Server struct { + pb.UnimplementedUpgradeClusterServer +} + +// Implements the Upgrade +func (s *Server) Upgrade(_ context.Context, req *pb.UpgradeRequest) (*pb.UpgradeResponse, error) { + //todo + return &pb.UpgradeResponse{}, nil +}