Skip to content

Commit

Permalink
apply manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunodeluk committed Apr 21, 2022
1 parent 20f0a18 commit 26e2175
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions configmanager/client/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"io/fs"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/rest"
"os"
"path/filepath"
)
Expand All @@ -19,6 +21,36 @@ type Kubernetes struct {
func (k *Kubernetes) Apply(ctx context.Context, path string) error {
objects, err := filesToObjects(path)
fmt.Printf("read %d objects", len(objects))

config, err := rest.InClusterConfig()
if err != nil {
return err
}

client, err := rest.RESTClientFor(config)
if err != nil {
return err
}

fmt.Println("starting applying process")
for i, obj := range objects {
fmt.Printf("Applying manifest %d...\n", i+1)
applyObject := obj.DeepCopy()
b, err := applyObject.MarshalJSON()
if err != nil {
return err
}

req := client.
Patch(types.ApplyPatchType).
Body(b).
Do(ctx)

if req.Error() != nil {
return err
}
}

return err
}

Expand Down

0 comments on commit 26e2175

Please sign in to comment.