Skip to content

Commit

Permalink
fix: apply resource definition format (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
akijakya authored Mar 9, 2023
1 parent 6cd7598 commit fd3ed96
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions internal/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func NewApplyCommand() *cobra.Command {
var rawResources [][]byte

for _, file := range files {

var manifest io.Reader

if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") {
Expand Down Expand Up @@ -72,7 +71,7 @@ func NewApplyCommand() *cobra.Command {
break
}

var resource interface{}
var resource map[string]interface{}

switch obj.GetKind() {
case "Pod":
Expand All @@ -93,7 +92,10 @@ func NewApplyCommand() *cobra.Command {
}
}

resource = pod
resource, err = runtime.DefaultUnstructuredConverter.ToUnstructured(pod)
if err != nil {
return err
}

case "Deployment":
deployment := new(appsv1.Deployment)
Expand All @@ -113,9 +115,16 @@ func NewApplyCommand() *cobra.Command {
}
}

resource = deployment
resource, err = runtime.DefaultUnstructuredConverter.ToUnstructured(deployment)
if err != nil {
return err
}

default:
resource = obj
resource, err = runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return err
}
}

rawResource, err := yaml.Marshal(resource)
Expand Down Expand Up @@ -182,12 +191,13 @@ func buildImage(goFiles []string) (string, error) {
imageTag := fmt.Sprintf("kurun-%x", hash.Sum(nil))
directory := "/tmp/kurun/" + imageTag

os.MkdirAll(directory, os.ModePerm)
err := os.MkdirAll(directory, os.ModePerm)
if err != nil {
return "", err
}

goBuildArgs := []string{"build", "-o", directory + "/main"}
for _, gofile := range goFiles {
goBuildArgs = append(goBuildArgs, gofile)
}
goBuildArgs = append(goBuildArgs, goFiles...)
goBuildCommand := exec.Command("go", goBuildArgs...)
goBuildCommand.Stderr = os.Stderr
goBuildCommand.Stdout = os.Stdout
Expand Down

0 comments on commit fd3ed96

Please sign in to comment.