Skip to content

Commit

Permalink
Add workload daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Sep 11, 2020
1 parent 22b95b7 commit 789ce7e
Show file tree
Hide file tree
Showing 9 changed files with 1,299 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Dockerfile.workload-daemon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 The Kubernetes Authors. All rights reserved.
#
# 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.

# This image requires ca-certificate, which is pre-installed in distroless.
FROM gcr.io/distroless/static:latest

ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN
ENTRYPOINT ["/ARG_BIN"]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CONTAINER_BINARIES ?= \
echo \
fuzzer \
glbc \
workload-controller
workload-controller \
workload-daemon

# Latest commit hash for current branch.
GIT_COMMIT := $(shell git rev-parse HEAD)
Expand Down
76 changes: 76 additions & 0 deletions cmd/workload-daemon/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2020 The Kubernetes 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"
"fmt"
"os"
"time"

daemon "k8s.io/ingress-gce/pkg/experimental/workload/daemon"
gce "k8s.io/ingress-gce/pkg/experimental/workload/daemon/provider/gce"
"k8s.io/klog"

// GCP Authentication
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

func main() {
cmdSet := flag.NewFlagSet("cmd", flag.ExitOnError)
provider := cmdSet.String("provider", "gce", "The provider of this external workload.")
updateInterval := cmdSet.Duration("interval", 30*time.Second, "The resync interval.")

if len(os.Args) < 2 {
outputHelp()
return
}
cmdSet.Parse(os.Args[2:])
if *provider != "gce" {
klog.Fatalf("Current implementation only supports gce provider.")
}

switch os.Args[1] {
case "get-credentials":
vm, err := gce.NewVM()
if err != nil {
klog.Fatalf("unable to initialize GCE VM: %+v", err)
}
credentials, err := vm.Credentials()
if err != nil {
klog.Fatalf("unable to get credentials: %+v", err)
}
daemon.OutputCredentials(credentials)
return
case "start":
klog.V(0).Infof("Workload daemon started")
vm, err := gce.NewVM()
if err != nil {
klog.Fatalf("unable to initialize GCE VM: %+v", err)
}
daemon.RunDaemon(vm, vm, *updateInterval)
return
default:
outputHelp()
return
}
}

func outputHelp() {
fmt.Printf("Usage: %v [command]\n", os.Args[0])
fmt.Printf("command:\n start\n get-credentials\n")
}
Loading

0 comments on commit 789ce7e

Please sign in to comment.