Skip to content

Commit

Permalink
feat: add apiversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tangx committed Mar 12, 2024
1 parent e3d29c5 commit 03bb315
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pkg/kustz/apiversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kustz

type Metadata struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
}
4 changes: 2 additions & 2 deletions pkg/kustz/k_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func (kz *Config) KubePod() corev1.PodTemplateSpec {
Spec: corev1.PodSpec{
Containers: kz.KubeContainer(),
ImagePullSecrets: toImagePullSecrets(kz.Service.ImagePullSecrets),
DNSConfig: toPodDNSConfig(&kz.DNS),
DNSPolicy: toDNSPolicy(&kz.DNS),
DNSConfig: toPodDNSConfig(kz.DNS),
DNSPolicy: toDNSPolicy(kz.DNS),
},
}
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/kustz/kustz.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apiVersion: kustz/v1

namespace: demo-demo
name: srv-webapp-demo

Expand Down Expand Up @@ -41,7 +43,7 @@ service:
# dns:
# config:
# nameservers:
# - 10.133.10.55 # align internat dns
# - 10.133.10.55
# searches:
# - ns1.svc.cluster.local
# - my.dns.search.suffix
Expand All @@ -58,7 +60,6 @@ ingress:
- http://api.example.com/ping?tls=star-example-com&svc=srv-webapp-demo:8080
- http://api.balala.com/*


# https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/configmapgenerator/
configmaps:
envs:
Expand All @@ -76,10 +77,10 @@ secrets:
files:
- name: srv-webapp-demo-files
files:
- tls.crt=catsecret/tls.crt
- tls.key=secret/tls.key
- tls.crt=catsecret/tls.crt
- tls.key=secret/tls.key
type: "kubernetes.io/tls"
- name: aliyun-repo
files:
- .dockerconfigjson=docker-config.json
type: kubernetes.io/dockerconfigjson
type: kubernetes.io/dockerconfigjson
9 changes: 9 additions & 0 deletions pkg/kustz/kustz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ var (
kz = NewKustzFromConfig("./kustz.yml")
)

func Test_YamlMarshal(t *testing.T) {
b, err := kubeutils.YAMLMarshal(kz)
if err != nil {
panic(err)
}

fmt.Printf("%s\n", b)
}

func Test_KustzDeployment(t *testing.T) {
dep := kz.KubeDeployment()
output(dep)
Expand Down
18 changes: 14 additions & 4 deletions pkg/kustz/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import (
"github.com/tangx/kustz/pkg/kubeutils"
)

const (
APIVersion = "kustz/v1"
)

type Config struct {
Metadata `json:",inline"`

Name string `json:"name"`
Namespace string `json:"namespace"`
Service Service `json:"service"`
Ingress Ingress `json:"ingress"`
ConfigMaps Generator `json:"configmaps"`
Secrets Generator `json:"secrets"`
DNS DNS `json:"dns"`
Ingress Ingress `json:"ingress,omitempty"`
ConfigMaps Generator `json:"configmaps,omitempty"`
Secrets Generator `json:"secrets,omitempty"`
DNS *DNS `json:"dns,omitempty"`
}

func NewKustzFromConfig(cfg string) *Config {
Expand All @@ -28,6 +34,10 @@ func NewKustzFromConfig(cfg string) *Config {
panic(err)
}

if kz.Metadata.APIVersion == "" {
kz.Metadata.APIVersion = APIVersion
}

return kz
}

Expand Down

0 comments on commit 03bb315

Please sign in to comment.