mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-09-27 10:02:10 +08:00
Adding function to output the CLI required YAML for manifests.
- Adding helper structs and tags
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -16,6 +17,57 @@ type ArtifactRepositoryS3Config struct {
|
|||||||
AccessKey string `yaml:"accessKey"`
|
AccessKey string `yaml:"accessKey"`
|
||||||
Secretkey string `yaml:"secretKey"`
|
Secretkey string `yaml:"secretKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArtifactRepositoryS3Provider is meant to be used
|
||||||
|
// by the CLI. CLI will marshal this struct into the correct
|
||||||
|
// YAML structure for k8s configmap / secret.
|
||||||
|
type ArtifactRepositoryS3Provider struct {
|
||||||
|
KeyFormat string `yaml:"keyFormat"`
|
||||||
|
Bucket string
|
||||||
|
Endpoint string
|
||||||
|
Insecure bool
|
||||||
|
Region string
|
||||||
|
AccessKeySecret ArtifactRepositorySecret `yaml:"accessKeySecret"`
|
||||||
|
SecretKeySecret ArtifactRepositorySecret `yaml:"secretKeySecret"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArtifactRepositoryProviderConfig struct {
|
||||||
|
S3 ArtifactRepositoryS3Provider `yaml:"s3"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArtifactRepositorySecret struct {
|
||||||
|
Key string `yaml:"key"`
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArtifactRepositoryS3Config) MarshalToYaml() (error, string) {
|
||||||
|
builder := &strings.Builder{}
|
||||||
|
encoder := yaml.NewEncoder(builder)
|
||||||
|
encoder.SetIndent(6)
|
||||||
|
defer encoder.Close()
|
||||||
|
err := encoder.Encode(&ArtifactRepositoryProviderConfig{
|
||||||
|
S3: ArtifactRepositoryS3Provider{
|
||||||
|
KeyFormat: a.KeyFormat,
|
||||||
|
Bucket: a.Bucket,
|
||||||
|
Endpoint: a.Endpoint,
|
||||||
|
Insecure: a.Insecure,
|
||||||
|
Region: a.Region,
|
||||||
|
AccessKeySecret: ArtifactRepositorySecret{
|
||||||
|
Name: a.AccessKeySecret.Name,
|
||||||
|
Key: a.AccessKey,
|
||||||
|
},
|
||||||
|
SecretKeySecret: ArtifactRepositorySecret{
|
||||||
|
Name: a.SecretKeySecret.Name,
|
||||||
|
Key: a.Secretkey,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormatKey replaces placeholder values with their actual values and returns this string.
|
// FormatKey replaces placeholder values with their actual values and returns this string.
|
||||||
|
Reference in New Issue
Block a user