Created
September 16, 2021 07:40
-
-
Save komuw/a20fd6714c161fed3db32fa789e3d4f7 to your computer and use it in GitHub Desktop.
create a golang k8(kubernetes) struct from yaml file
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
# gotten from; https://github.com/jetstack/cert-manager/releases/download/v1.3.3/cert-manager.yamlhttps://github.com/jetstack/cert-manager/releases/download/v1.3.3/cert-manager.yaml | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: cert-manager | |
app.kubernetes.io/component: controller | |
app.kubernetes.io/instance: cert-manager | |
app.kubernetes.io/name: cert-manager | |
name: cert-manager | |
namespace: cert-manager | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app.kubernetes.io/component: controller | |
app.kubernetes.io/instance: cert-manager | |
app.kubernetes.io/name: cert-manager | |
template: | |
metadata: | |
annotations: | |
prometheus.io/path: /metrics | |
prometheus.io/port: "9402" | |
prometheus.io/scrape: "true" | |
labels: | |
app: cert-manager | |
app.kubernetes.io/component: controller | |
app.kubernetes.io/instance: cert-manager | |
app.kubernetes.io/name: cert-manager | |
spec: | |
containers: | |
- args: | |
- --v=2 | |
- --cluster-resource-namespace=$(POD_NAMESPACE) | |
- --leader-election-namespace=kube-system | |
env: | |
- name: POD_NAMESPACE | |
valueFrom: | |
fieldRef: | |
fieldPath: metadata.namespace | |
image: quay.io/jetstack/cert-manager-controller:v1.3.3 | |
imagePullPolicy: IfNotPresent | |
name: cert-manager | |
ports: | |
- containerPort: 9402 | |
protocol: TCP | |
resources: {} | |
serviceAccountName: cert-manager |
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
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/komuw/kama" | |
appsv1 "k8s.io/api/apps/v1" | |
v1 "k8s.io/api/core/v1" | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/apimachinery/pkg/util/yaml" | |
) | |
// wget -nc https://github.com/jetstack/cert-manager/releases/download/v1.3.3/cert-manager.yaml | |
func main() { | |
f, err := os.Open("cert-manager.yaml") | |
if err != nil { | |
panic(err) | |
} | |
k8sStruct := &appsv1.Deployment{} | |
buffSize := 9000_000 | |
err = yaml.NewYAMLOrJSONDecoder(f, buffSize).Decode(k8sStruct) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("k8sStruct:") | |
kama.Dirp(k8sStruct) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment