-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
82 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 was deleted.
Oops, something went wrong.
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,53 @@ | ||
package util | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" | ||
"io" | ||
"os" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func PersistShoot(path string, shoot *v1beta1.Shoot) error { | ||
writer, err := getWriter(path) | ||
if err != nil { | ||
return fmt.Errorf("unable to create file: %w", err) | ||
} | ||
|
||
b, err := yaml.Marshal(shoot) | ||
if err != nil { | ||
return fmt.Errorf("unable to marshal shoot: %w", err) | ||
} | ||
|
||
if _, err = writer.Write(b); err != nil { | ||
return fmt.Errorf("unable to write to file: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func getWriter(filePath string) (io.Writer, error) { | ||
file, err := os.Create(filePath) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create file: %w", err) | ||
} | ||
return file, nil | ||
} | ||
|
||
func PersistGraphQL(path string, mutation gqlschema.ProvisionRuntimeInput) error { | ||
writer, err := getWriter(path) | ||
if err != nil { | ||
return fmt.Errorf("unable to create file: %w", err) | ||
} | ||
|
||
b, err := json.Marshal(mutation) | ||
if err != nil { | ||
return fmt.Errorf("unable to marshal GraphQL mutation: %w", err) | ||
} | ||
|
||
if _, err = writer.Write(b); err != nil { | ||
return fmt.Errorf("unable to write to file: %w", err) | ||
} | ||
return nil | ||
} |