1
1
package main
2
2
3
3
import (
4
- "fmt"
5
4
"log"
6
5
"os"
7
6
"path/filepath"
8
7
9
8
"gopkg.in/alecthomas/kingpin.v2"
9
+ "gopkg.in/yaml.v2"
10
10
11
11
"github.com/square/p2/pkg/artifact"
12
12
"github.com/square/p2/pkg/auth"
@@ -15,6 +15,7 @@ import (
15
15
p2manifest "github.com/square/p2/pkg/manifest"
16
16
"github.com/square/p2/pkg/osversion"
17
17
"github.com/square/p2/pkg/pods"
18
+ "github.com/square/p2/pkg/preparer"
18
19
"github.com/square/p2/pkg/types"
19
20
"github.com/square/p2/pkg/uri"
20
21
"github.com/square/p2/pkg/version"
@@ -23,7 +24,7 @@ import (
23
24
var (
24
25
manifestURI = kingpin .Arg ("manifest" , "a path or url to a pod manifest that will be installed and launched immediately" ).URL ()
25
26
registryURI = kingpin .Arg ("registry" , "a URL to the registry to download artifacts from" ).URL ()
26
- isPreparerManifest = kingpin .Arg ( "isPreparerManifest " , "to install hooks from a P2-Preparer manifest" ).Bool ()
27
+ isPreparerManifest = kingpin .Flag ( "is-preparer-manifest " , "to install hooks from a P2-Preparer manifest" ).Bool ()
27
28
nodeName = kingpin .Flag ("node-name" , "the name of this node (default: hostname)" ).String ()
28
29
podRoot = kingpin .Flag ("pod-root" , "the root of the pods directory" ).Default (pods .DefaultPath ).String ()
29
30
hookRoot = kingpin .Flag ("hook-root" , "the root of the hook scripts directory" ).Default (hooks .DefaultPath ).String ()
@@ -37,7 +38,7 @@ func main() {
37
38
if * nodeName == "" {
38
39
hostname , err := os .Hostname ()
39
40
if err != nil {
40
- log .Fatalf ("error getting node name: %v" , err )
41
+ log .Fatalf ("Error getting node name: %v" , err )
41
42
}
42
43
* nodeName = hostname
43
44
}
@@ -48,12 +49,19 @@ func main() {
48
49
}
49
50
50
51
if * isPreparerManifest {
51
- config := manifest .GetConfig ()
52
- hooksManifest , ok := config ["hooks_manifest" ]
53
- if ok {
54
- manifest = hooksManifest .(p2manifest.Manifest )
55
- } else {
56
- fmt .Printf ("Error to read hooks manifest from P2-Preparer manifest: %v" , manifest )
52
+ preparerConfigBytes , err := yaml .Marshal (manifest .GetConfig ())
53
+ if err != nil {
54
+ log .Printf ("Unable to marshal preparer config: %v" , err )
55
+ }
56
+
57
+ preparerConfig , err := preparer .UnmarshalConfig (preparerConfigBytes )
58
+ if err != nil {
59
+ log .Printf ("Could not properly unmarshal p2-preparer config from YAML: %v" , err )
60
+ }
61
+
62
+ manifest , err = p2manifest .FromBytes ([]byte (preparerConfig .HooksManifest ))
63
+ if err != nil {
64
+ log .Fatalf ("Error to read hooks manifest from P2-Preparer manifest: %v" , manifest )
57
65
}
58
66
}
59
67
0 commit comments