-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore metallb admission (#400)
* fix: ignore metallb admission Set the metallb admission controller to ignore. Our IPAddressPools and L2Advertisements are static and work. The admission controller has a habit of not coming online and blocking the deploy. Ignoring its failures avoids this. Add a kustomize utility and refactor the metallb deploy to use it. * chore: fix kustomization fields Co-authored-by: Patryk Małek <[email protected]>
- Loading branch information
Showing
3 changed files
with
114 additions
and
5 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
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
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,58 @@ | ||
package kubectl | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/ghodss/yaml" | ||
"sigs.k8s.io/kustomize/api/krusty" | ||
"sigs.k8s.io/kustomize/api/types" | ||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
) | ||
|
||
// GetKustomizedManifest takes a kustomization and any number of manifest readers. It adds the manifests to the | ||
// kustomization's resources and returns a reader with the rendered kustomization. | ||
func GetKustomizedManifest(kustomization types.Kustomization, manifests ...io.Reader) (io.Reader, error) { | ||
workDir, err := os.MkdirTemp("", "ktf.") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer os.RemoveAll(workDir) | ||
for i, manifest := range manifests { | ||
orig, err := io.ReadAll(manifest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = os.WriteFile(filepath.Join(workDir, fmt.Sprintf("resource_%d.yaml", i)), orig, 0o600) //nolint:gomnd | ||
if err != nil { | ||
return nil, err | ||
} | ||
kustomization.Resources = append(kustomization.Resources, fmt.Sprintf("resource_%d.yaml", i)) | ||
} | ||
marshalled, err := yaml.Marshal(kustomization) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = os.WriteFile(filepath.Join(workDir, "kustomization.yaml"), marshalled, 0o600) //nolint:gomnd | ||
if err != nil { | ||
return nil, err | ||
} | ||
kustomized, err := runKustomize(workDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return bytes.NewReader(kustomized), nil | ||
} | ||
|
||
// runKustomize runs kustomize on a path and returns the YAML output. | ||
func runKustomize(path string) ([]byte, error) { | ||
k := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) | ||
m, err := k.Run(filesys.MakeFsOnDisk(), path) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
return m.AsYaml() | ||
} |