This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (78 loc) · 2.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"context"
"os"
"github.com/concourse/porter/blobio"
cwatch "github.com/concourse/porter/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"code.cloudfoundry.org/lager"
"github.com/jessevdk/go-flags"
)
type PushCommand struct {
PodName string `required:"true" long:"pod-name" positional-args:"yes" description:"Pod to watch"`
ContainerName string `required:"true" long:"container-name" positional-args:"yes" description:"Container to wait till completion"`
SourcePath string `required:"true" long:"source-path" description:"Location to fetch input blobs from within the bucket."`
BucketURL string `required:"true" long:"bucket-url" description:"Location of the bucket to fetch blobs from"`
DestinationPath string `required:"true" long:"destination-path" description:"Path to inflate with fetched blobs"`
}
func (pc *PushCommand) Execute(args []string) error {
logger.Debug("push-execute", lager.Data{
"podname": pc.PodName,
"containername": pc.ContainerName,
})
config, err := rest.InClusterConfig()
if err != nil {
logger.Error("failed to retrieve cluster config", err)
return err
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
logger.Error("failed to create client with fetched config", err)
return err
}
watcher := cwatch.ContainerWatcher{
Client: clientset,
ContainerName: pc.ContainerName,
PodName: pc.PodName,
}
err = watcher.Wait(logger)
if err != nil {
return err
}
bucketConfig := blobio.BucketConfig{
URL: pc.BucketURL,
}
err = blobio.Push(
logger,
context.Background(),
bucketConfig,
pc.SourcePath,
pc.DestinationPath,
)
if err != nil {
logger.Error("error-pushing", err)
return err
}
return nil
}
var (
logger lager.Logger
Push PushCommand
)
func main() {
logger = lager.NewLogger("porter-push")
sink := lager.NewWriterSink(os.Stderr, lager.DEBUG)
logger.RegisterSink(sink)
parser := flags.NewParser(&Push, flags.HelpFlag|flags.PrintErrors|flags.IgnoreUnknown)
parser.NamespaceDelimiter = "-"
_, err := parser.Parse()
if err != nil {
os.Exit(1)
}
err = Push.Execute(os.Args)
if err != nil {
os.Exit(1)
}
os.Exit(0)
}