Skip to content

Commit

Permalink
Add remote work processor executable and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Nizamski committed May 17, 2023
1 parent d40fce9 commit 793f213
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
testbin/
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.20-bullseye as builder

WORKDIR /autopi

# Copy the Go Modules manifests
COPY . .

# Build
RUN CGO_ENABLED=0 make build

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static-debian11:nonroot

WORKDIR /
COPY --from=builder /autopi/remote-work-processor .

USER 65532:65532

ENTRYPOINT ["/remote-work-processor"]
96 changes: 96 additions & 0 deletions cmd/remote-work-processor/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright 2021.
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"
// "os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.

"log"
"os"

_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

// "sigs.k8s.io/controller-runtime/pkg/healthz"
// "sigs.k8s.io/controller-runtime/pkg/log/zap"
// "github.com/SAP/remote-work-processor/kubernetes/controllers"
"github.com/SAP/remote-work-processor/internal/grpc"
"github.com/SAP/remote-work-processor/internal/grpc/processors"
"github.com/SAP/remote-work-processor/internal/kubernetes/controller"
"github.com/SAP/remote-work-processor/internal/kubernetes/metadata"
//+kubebuilder:scaffold:imports
)

var (
scheme = runtime.NewScheme()
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

func main() {
metadata.InitRemoteWorkProcessorMetadata()
config := getKubeConfig()

e := controller.CreateManagerEngine(scheme, config)
processors.InitProcessorFactory(e)
grpc.InitRemoteWorkProcessorGrpcClient()

opc := grpc.Client.Receive()

for {
op := <-opc
p, err := processors.Factory.CreateProcessor(op)
if err != nil {
log.Fatalf("Error occurred while creating operation processor: %v\n", err)
}

res := <-p.Process()
if res.Err != nil {
log.Fatalf("Error occurred while processing operation: %v\n", err)
}

if res.Result != nil {
grpc.Client.Send(res.Result)
}
}
}

func getKubeConfig() *rest.Config {
rules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}

kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)

config, err := kubeConfig.ClientConfig()
if err != nil {
os.Exit(1)
}

return config
}

0 comments on commit 793f213

Please sign in to comment.