-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add usage of kustomize for KIC's webhook config generation
- Loading branch information
Showing
3 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package kic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os/exec" | ||
) | ||
|
||
// BuildKustomizeForURLAndRef runs kustomize build for the provided URL and ref. | ||
// It returns the output of the kustomize build command. | ||
func BuildKustomizeForURLAndRef(ctx context.Context, url, ref string) ([]byte, error) { | ||
kustomizeResourceURL := fmt.Sprintf("%s?ref=%s", url, ref) | ||
|
||
log.Printf("Running 'kustomize build %s'\n", kustomizeResourceURL) | ||
cmd := exec.CommandContext(ctx, "kustomize", "build", kustomizeResourceURL) | ||
stdout, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
stderr, err := cmd.StderrPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := cmd.Start(); err != nil { | ||
return nil, fmt.Errorf("failed to start kustomize command %v: %w", cmd, err) | ||
} | ||
b, err := io.ReadAll(stdout) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read kustomize stdout: %w", err) | ||
} | ||
berr, err := io.ReadAll(stderr) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read kustomize stderr: %w", err) | ||
} | ||
if err := cmd.Wait(); err != nil { | ||
return nil, fmt.Errorf("failed to wait for kustomize to finish, output %s: %w", string(berr), err) | ||
} | ||
|
||
return b, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
pkg/utils/kubernetes/resources/validatingwebhookconfig/zz_generated_kic_ge3_2.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.