Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions api/v1/genesissecret_types.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
package v1

type GenesisSecret struct {
Spec GenesisSecretSpec `yaml:"spec"`
Spec GenesisSecretSpec `json:"spec"`
}

type GenesisSecretSpec struct {
Provider string `yaml:"provider"`
Secrets []GenesisSecretGenerate `yaml:"secrets"`
Outputs []GenesisSecretOutput `yaml:"outputs"`
Provider string `json:"provider"`
Secrets []GenesisSecretGenerate `json:"secrets"`
Outputs []GenesisSecretOutput `json:"outputs"`
}

type GenesisSecretGenerate struct {
// PreferLabelはID->ValueのマッピングではなくLabel->Valueを作る
// カスタムのkey-valueを作るとIDがランダム文字列になるので、それを可能にするために定義する
PreferLabel bool `yaml:"preferLabel"`
URI string `yaml:"uri"`
Items map[string]GenesisSecretGenerateItem `yaml:"items"`
PreferLabel bool `json:"preferLabel"`
URI string `json:"uri"`
Items map[string]GenesisSecretGenerateItem `json:"items"`
}

type GenesisSecretGenerateItem struct {
MapTo string `yaml:"mapTo"`
MapTo string `json:"mapTo"`
}

type GenesisSecretOutput struct {
Stdout *GenesisSecretOutputStdout `yaml:"stdout,omitempty"`
KubernetesSecret *GenesisSecretOutputKubernetesSecret `yaml:"kubernetesSecret,omitempty"`
Stdout *GenesisSecretOutputStdout `json:"stdout,omitempty"`
KubernetesSecret *GenesisSecretOutputKubernetesSecret `json:"kubernetesSecret,omitempty"`
}

type GenesisSecretOutputStdout struct{}

type GenesisSecretOutputKubernetesSecret struct {
Context string `yaml:"context"`
Namespace string `yaml:"namespace"`
Name string `yaml:"name"`
Labels map[string]string `yaml:"labels"`
Annotations map[string]string `yaml:"annotations"`
Context string `json:"context"`
Namespace string `json:"namespace"`
Name string `json:"name"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
// corev1.SecretType を指定する
Type string `yaml:"type"`
}

func (GenesisSecret) GetKind() string {
return "GenesisSecret"
}
func (GenesisSecret) GetName() string {
return ""
Type string `json:"type"`
}
12 changes: 1 addition & 11 deletions api/v1/genesissecret_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import (
"testing"

"gopkg.in/yaml.v3"
"sigs.k8s.io/yaml"
)

func TestGenesisSecret_RoundTrip(t *testing.T) {
Expand Down Expand Up @@ -98,13 +98,3 @@ func TestGenesisSecretOutput_StdoutOnly(t *testing.T) {
}
}

func TestGenesisSecret_Kind(t *testing.T) {
t.Parallel()
gs := GenesisSecret{}
if gs.GetKind() != "GenesisSecret" {
t.Errorf("GetKind = %q", gs.GetKind())
}
if gs.GetName() != "" {
t.Errorf("GetName = %q, want empty", gs.GetName())
}
}
28 changes: 14 additions & 14 deletions api/v1/hint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ const (
// MergeVarsWithHintの実行時に、個別varの検証後に評価されます。
type HintRule struct {
// Type はルールの種別です。現在は "oneof_required" のみ対応。
Type HintRuleType `yaml:"type" json:"type"`
Type HintRuleType `json:"type"`
// Vars はルールの対象となるvar名のリストです。2件以上が必要です。
Vars []string `yaml:"vars" json:"vars"`
Vars []string `json:"vars"`
// Message はバリデーションエラー時に表示するカスタムメッセージです。
Message string `yaml:"message,omitempty" json:"message,omitempty"`
Message string `json:"message,omitempty"`
}

// TazunaHint はtazuna.hint.yamlのルートリソースです
type TazunaHint struct {
APIVersion string `yaml:"apiVersion" json:"APIVersion"`
Kind string `yaml:"kind" json:"Kind"`
Vars map[string]HintVar `yaml:"vars" json:"Vars"`
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Vars map[string]HintVar `json:"vars"`
// Rules はvar横断のトップレベルバリデーションルールです。
Rules []HintRule `yaml:"rules,omitempty" json:"Rules,omitempty"`
Rules []HintRule `json:"rules,omitempty"`
}

// HintVar はhint varsの定義です
type HintVar struct {
Type HintVarType `yaml:"type" json:"type"`
Required bool `yaml:"required" json:"required"`
Default any `yaml:"default,omitempty" json:"default,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Type HintVarType `json:"type"`
Required bool `json:"required"`
Default any `json:"default,omitempty"`
Description string `json:"description,omitempty"`
// Format はstring型varに対するフォーマット検証ルールです。
// string型以外のvarに指定するとValidateHintでエラーになります。
// 値が空文字列(ゼロ値注入を含む)の場合、検証はスキップされます。
Format HintFormat `yaml:"format,omitempty" json:"format,omitempty"`
Format HintFormat `json:"format,omitempty"`
// RequiredWith は、指定されたvarのいずれかがユーザーから提供された場合に、
// このvarも必須になることを示します。
// required:trueとの併用は矛盾するためValidateHintでエラーになります。
RequiredWith []string `yaml:"required_with,omitempty" json:"required_with,omitempty"`
RequiredWith []string `json:"required_with,omitempty"`
// RequiredWithout は、指定されたvarが全てユーザーから未提供の場合に、
// このvarが必須になることを示します。
// required:trueとの併用は矛盾するためValidateHintでエラーになります。
RequiredWithout []string `yaml:"required_without,omitempty" json:"required_without,omitempty"`
RequiredWithout []string `json:"required_without,omitempty"`
}
2 changes: 1 addition & 1 deletion api/v1/hint_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import (
"testing"

"gopkg.in/yaml.v3"
"sigs.k8s.io/yaml"
)

func TestTazunaHint_RoundTrip(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions api/v1/oras_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ type ManifestORAS struct {
// Reference はOCI artifactのreferenceを指定します。
// tag形式 (`ghcr.io/example/foo:v1.0.0`) と digest形式
// (`ghcr.io/example/foo@sha256:...`) の両方を受け付けます。
Reference string `yaml:"reference"`
Reference string `json:"reference"`
// Target はartifact展開後のルートからの相対サブパスを指定します。
// 省略時はrootを指します。
Target string `yaml:"target,omitempty"`
Target string `json:"target,omitempty"`
// PlainHTTP はregistryへの接続にHTTP (非TLS) を使うかどうかを指定します。
PlainHTTP bool `yaml:"plainHTTP,omitempty"`
PlainHTTP bool `json:"plainHTTP,omitempty"`
// InsecureSkipVerify はregistry接続時のTLS証明書検証をスキップします。
InsecureSkipVerify bool `yaml:"insecureSkipVerify,omitempty"`
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
// Auth はregistryの認証情報をoverrideします。省略時は docker config.json を使用します。
Auth *ORASAuth `yaml:"auth,omitempty"`
Auth *ORASAuth `json:"auth,omitempty"`
// Delegate はpull後の委譲先managerの設定を指定します。
Delegate ORASDelegate `yaml:"delegate"`
Delegate ORASDelegate `json:"delegate"`
}

// ORASAuth はORAS pull時の認証情報のoverrideを表します。
type ORASAuth struct {
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}

// ORASDelegate はORAS managerが委譲する先のmanager設定を表します。
type ORASDelegate struct {
// Type は委譲先managerの種別 (helmfile / kustomize) を指定します。
Type ORASDelegateType `yaml:"type"`
Type ORASDelegateType `json:"type"`
// Helmfile は Type が helmfile の場合に委譲先に渡す設定です。
Helmfile *ManifestHelmfile `yaml:"helmfile,omitempty"`
Helmfile *ManifestHelmfile `json:"helmfile,omitempty"`
// Kustomize は Type が kustomize の場合に委譲先に渡す設定です。
Kustomize *ManifestKustomize `yaml:"kustomize,omitempty"`
Kustomize *ManifestKustomize `json:"kustomize,omitempty"`
}
2 changes: 1 addition & 1 deletion api/v1/oras_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import (
"testing"

"gopkg.in/yaml.v3"
"sigs.k8s.io/yaml"
)

func TestManifestORAS_RoundTrip_Tag(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions api/v1/provider_types.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package v1

type Provider struct {
Spec ProviderSpec `yaml:"spec"`
Spec ProviderSpec `json:"spec"`
}

type ProviderSpec struct {
Requirements []ProviderRequirement `yaml:"requirements"`
Requirements []ProviderRequirement `json:"requirements"`
}

type ProviderRequirement struct {
Name string `yaml:"name"`
Command []string `yaml:"command"`
Name string `json:"name"`
Command []string `json:"command"`
}

func (Provider) GetKind() string {
Expand Down
2 changes: 1 addition & 1 deletion api/v1/provider_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import (
"testing"

"gopkg.in/yaml.v3"
"sigs.k8s.io/yaml"
)

func TestProvider_RoundTrip(t *testing.T) {
Expand Down
87 changes: 50 additions & 37 deletions api/v1/tazuna_types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
package v1

const (
// TazunaAPIVersion は Tazuna リソースが取りうる apiVersion の正規値です。
TazunaAPIVersion = "tazuna.pepabo.com/v1"
// TazunaKind は Tazuna リソースが取りうる kind の正規値です。
TazunaKind = "Tazuna"
)

// Tazuna はtazuna applyの挙動を制御するルートリソースです
type Tazuna struct {
Spec TazunaSpec `yaml:"spec"`
// APIVersion は Kubernetes manifest と同形式の TypeMeta フィールドです。
// 設定する場合は TazunaAPIVersion と一致している必要があります。
APIVersion string `json:"apiVersion,omitempty"`
// Kind は Kubernetes manifest と同形式の TypeMeta フィールドです。
// 設定する場合は TazunaKind と一致している必要があります。
Kind string `json:"kind,omitempty"`
Spec TazunaSpec `json:"spec"`
}

// ContextMatchMode はcontext_matchesの評価モードを定義します
Expand All @@ -18,46 +31,46 @@ const (
type TazunaSpec struct {
// ContextMatchesは現在のkubeconfigコンテキスト名がマッチすべき正規表現パターンのリストです
// 指定した場合、apply/destroy時にコンテキスト名がパターンにマッチしないとエラーになります
ContextMatches []string `yaml:"context_matches,omitempty"`
ContextMatches []string `json:"context_matches,omitempty"`
// ContextMatchModeはcontext_matchesの評価モードです("or" または "and"、デフォルトは "or")
ContextMatchMode ContextMatchMode `yaml:"context_match_mode,omitempty"`
Manifests []Manifest `yaml:"manifests"`
ContextMatchMode ContextMatchMode `json:"context_match_mode,omitempty"`
Manifests []Manifest `json:"manifests"`
// Testsはすべてのマニフェスト適用が終わったあとに実行されます
Tests []TestPluginSpec `yaml:"tests"`
Tests []TestPluginSpec `json:"tests"`
}

// IncludeFile はincludeするファイルを定義します
type IncludeFile struct {
// Path はincludeするファイルのパス(tazuna.yamlからの相対パス)
Path string `yaml:"path"`
Path string `json:"path"`
}

// Manifest はtazunaのマニフェスト管理方式を定義します
type Manifest struct {
Name string `yaml:"name,omitempty"` // マニフェストの名前
Description string `yaml:"description,omitempty"` // マニフェストの説明
Name string `json:"name,omitempty"` // マニフェストの名前
Description string `json:"description,omitempty"` // マニフェストの説明

// Includes はincludeするファイルのリストを指定します
// includesが指定された場合、他のフィールド(Type, Path, Tags など)は無視されます
Includes []IncludeFile `yaml:"includes,omitempty"`
Includes []IncludeFile `json:"includes,omitempty"`

// Path はマニフェストのパスを指定します
// GenesisSecretの場合はGenesisSecretのリソースマニフェストのパス
// Kustomizeの場合はkustomization.yamlがあるディレクトリ
// Helmfileの場合はhelmfile.yamlがあるディレクトリ
Path string `yaml:"path"`
Type ManifestType `yaml:"type"`
Path string `json:"path"`
Type ManifestType `json:"type"`
// Tagsはマニフェストに付与するタグを指定します
// タグはマニフェストの選択に利用できます
// 例えば、`tazuna apply --tags foo,bar`とすると、fooとbarのタグが付与されたマニフェストのみが適用されます
Tags []string `yaml:"tags,omitempty"`
Kustomize *ManifestKustomize `yaml:"kustomize,omitempty"`
GenesisSecret *ManifestGenesisSecret `yaml:"genesisSecret,omitempty"`
Helmfile *ManifestHelmfile `yaml:"helmfile,omitempty"`
Parallel *ManifestParallel `yaml:"parallel,omitempty"`
ORAS *ManifestORAS `yaml:"oras,omitempty"`
Tags []string `json:"tags,omitempty"`
Kustomize *ManifestKustomize `json:"kustomize,omitempty"`
GenesisSecret *ManifestGenesisSecret `json:"genesisSecret,omitempty"`
Helmfile *ManifestHelmfile `json:"helmfile,omitempty"`
Parallel *ManifestParallel `json:"parallel,omitempty"`
ORAS *ManifestORAS `json:"oras,omitempty"`
// Testsはマニフェストapply後に行われる各種テストを記載します
Tests []TestPluginSpec `yaml:"tests"`
Tests []TestPluginSpec `json:"tests"`
}

type ManifestType string
Expand All @@ -71,18 +84,18 @@ const (
)

type ManifestKustomize struct {
DefaultNamespace string `yaml:"defaultNamespace,omitempty"` // kustomize assetsのデフォルトネームスペース
DefaultNamespace string `json:"defaultNamespace,omitempty"` // kustomize assetsのデフォルトネームスペース
}

type ManifestGenesisSecret struct{}
type ManifestHelmfile struct {
IncludeCRDs bool `yaml:"includeCRDs"`
Vars map[string]HelmFileVar `yaml:"vars,omitempty"`
DefaultNamespace string `yaml:"defaultNamespace,omitempty"` // helmfile assetsのデフォルトネームスペース
ExtraValueFiles []string `yaml:"extraValueFiles,omitempty"` // 追加のvalue filesを指定
Wait bool `yaml:"wait,omitempty"` // helmfile syncに--waitオプションを渡す
TimeoutSeconds int `yaml:"timeoutSeconds,omitempty"` // リソースのReady待機のタイムアウト秒数
KubeVersion string `yaml:"kubeVersion,omitempty"` // helm templateに渡す--kube-versionの値
IncludeCRDs bool `json:"includeCRDs"`
Vars map[string]HelmFileVar `json:"vars,omitempty"`
DefaultNamespace string `json:"defaultNamespace,omitempty"` // helmfile assetsのデフォルトネームスペース
ExtraValueFiles []string `json:"extraValueFiles,omitempty"` // 追加のvalue filesを指定
Wait bool `json:"wait,omitempty"` // helmfile syncに--waitオプションを渡す
TimeoutSeconds int `json:"timeoutSeconds,omitempty"` // リソースのReady待機のタイムアウト秒数
KubeVersion string `json:"kubeVersion,omitempty"` // helm templateに渡す--kube-versionの値
}

func DefaultHelmfile() *ManifestHelmfile {
Expand All @@ -104,22 +117,22 @@ const (
type HelmFileVar struct {
// Fromはどこからhelmfile varの値を取得するかを指定します。
// 現状は `env` と `op`, `static` をサポートしています
From string `yaml:"from,omitempty"`
Op *OnePasswordVaultSelector `yaml:"op,omitempty"`
Static *string `yaml:"static,omitempty"` // staticな値を指定する
StaticSlice []string `yaml:"staticSlice,omitempty"` // staticなslice値を指定する
StaticMap map[string]string `yaml:"staticMap,omitempty"` // staticなmap値を指定する
Env *string `yaml:"env,omitempty"` // 環境変数から値を取得する
From string `json:"from,omitempty"`
Op *OnePasswordVaultSelector `json:"op,omitempty"`
Static *string `json:"static,omitempty"` // staticな値を指定する
StaticSlice []string `json:"staticSlice,omitempty"` // staticなslice値を指定する
StaticMap map[string]string `json:"staticMap,omitempty"` // staticなmap値を指定する
Env *string `json:"env,omitempty"` // 環境変数から値を取得する
}

type OnePasswordVaultSelector struct {
Key string `yaml:"key"` // 1PasswordのFieldをIDかLabelのどちらから取ってくるか
Vault string `yaml:"vault"` // 1PasswordのVault名
Item string `yaml:"item"` // 1PasswordのItem名
Field string `yaml:"field"` // 1PasswordのField名
Key string `json:"key"` // 1PasswordのFieldをIDかLabelのどちらから取ってくるか
Vault string `json:"vault"` // 1PasswordのVault名
Item string `json:"item"` // 1PasswordのItem名
Field string `json:"field"` // 1PasswordのField名
}

type ManifestParallel struct {
// Childrenはマニフェストの子マニフェストを定義します
Children []Manifest `yaml:"children,omitempty"`
Children []Manifest `json:"children,omitempty"`
}
2 changes: 1 addition & 1 deletion api/v1/tazuna_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import (
"testing"

"gopkg.in/yaml.v3"
"sigs.k8s.io/yaml"
)

func roundTripTazuna(t *testing.T, src Tazuna) Tazuna {
Expand Down
Loading