@@ -4,16 +4,14 @@ package main
44
55import (
66 "bytes"
7- "context"
87 "flag"
9- "fmt "
8+ "log "
109 "os"
1110 "path"
1211
1312 "gopkg.in/yaml.v2"
1413 corev1 "k8s.io/api/core/v1"
1514 yamlDecode "k8s.io/apimachinery/pkg/util/yaml"
16- ctrl "sigs.k8s.io/controller-runtime"
1715)
1816
1917type HelmChartFromConfigMap struct {
@@ -31,8 +29,6 @@ type HelmChartsConfig struct {
3129 Repositories map [string ]Repository `yaml:"repositories,omitempty"`
3230}
3331
34- var log = ctrl .LoggerFrom (context .Background ())
35-
3632func main () {
3733 args := os .Args
3834 var (
@@ -46,27 +42,32 @@ func main() {
4642 "input configmap file to create the mindthegap repo file from" )
4743 err := flagSet .Parse (args [1 :])
4844 if err != nil {
49- log .Error (err , "failed to parse args" )
45+ log .Fatalln ("failed to parse args:" , err )
46+ }
47+ if outputFile == "" {
48+ log .Fatalln ("output file is required" )
49+ }
50+ if inputConfigMapFile == "" {
51+ log .Fatalln ("input configmap file is required" )
5052 }
5153 fullPath := inputConfigMapFile
5254 if ! path .IsAbs (fullPath ) {
5355 wd , err := os .Getwd ()
5456 if err != nil {
55- log .Error (err , "failed to get wd" )
56- return
57+ log .Fatalln ("failed to get wd:" , err )
5758 }
5859 fullPath = path .Join (wd , inputConfigMapFile )
5960 }
6061 f , err := os .Open (fullPath )
6162 if err != nil {
62- log .Error (err , "failed to open file" )
63- return
63+ log .Fatalln ("failed to open file:" , err )
6464 }
6565 defer f .Close ()
6666 cm := & corev1.ConfigMap {}
6767 err = yamlDecode .NewYAMLOrJSONDecoder (f , 1024 ).Decode (cm )
6868 if err != nil {
69- log .Error (err , fmt .Sprintf ("failed to unmarshal file %s" , fullPath ))
69+ f .Close ()
70+ log .Fatalf ("failed to unmarshal file %s: %v\n " , fullPath , err )
7071 }
7172 out := HelmChartsConfig {
7273 map [string ]Repository {},
@@ -75,8 +76,7 @@ func main() {
7576 var settings HelmChartFromConfigMap
7677 err = yaml .Unmarshal ([]byte (info ), & settings )
7778 if err != nil {
78- log .Error (err , "failed unmarshl settings" )
79- return
79+ log .Fatalln ("failed to unmarshal settings:" , err )
8080 }
8181 out .Repositories [settings .Name ] = Repository {
8282 RepoURL : settings .Repository ,
@@ -89,23 +89,23 @@ func main() {
8989 }
9090 b , err := yaml .Marshal (out )
9191 if err != nil {
92- log .Error ( err , fmt . Sprintf ( "failed to marshal obj %v " , out ) )
92+ log .Fatalf ( "failed to marshal obj %+v: %v " , out , err )
9393 }
9494 fullOutputfilePath := outputFile
9595 if ! path .IsAbs (outputFile ) {
9696 wd , err := os .Getwd ()
9797 if err != nil {
98- log .Error ( err , "failed" )
98+ log .Fatalln ( "failed:" , err )
9999 }
100100 fullOutputfilePath = path .Join (wd , outputFile )
101101 }
102102 f , err = os .OpenFile (fullOutputfilePath , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0o666 )
103103 if err != nil {
104- log .Error ( err , "failed to create file" )
104+ log .Fatalln ( "failed to create file:" , err )
105105 }
106106 defer f .Close ()
107107 _ , err = bytes .NewBuffer (b ).WriteTo (f )
108108 if err != nil {
109- log .Error ( err , "failed to write to file" )
109+ log .Fatalln ( "failed to write to file:" , err )
110110 }
111111}
0 commit comments