<p>I’ve the following yaml which I need to apply using the K8S go sdk (and not k8s cli)
I didn’t find a way with the go sdk as it is custom resource, any idea how I can apply it via code to k8s?</p>
<p>This is the file</p>
<p>Any example will be very helpful!</p>
<pre><code>apiVersion: aps.dp.com/v1alpha1
kind: Edtack
metadata:
  name: ed01
  namespace: ctr
spec:
  intRef:
    name: evr
  stack:
  - name: vectnt
    namespace: aps
    path: https://packages.timber.io/helm/latest/vect-0.11.0.tgz
    valuesRef:
      name: vecvalues
  - name: ek
    namespace: lg
    path: rescharts/bing
  - name: apigw-gloo-ee
    namespace: apw
    path: https://common.cdn.repositories.cloud.sap/api-gateway/apigw-gloo-ee/apigw-gloo-ee-0.3.0.tgz
    pullSecretRef:
      name: svr-secret
    valuesSecretRef:
      name: apis
  - name: kuback
    namespace: kube-prom
    path: https://github.com/prometheus-community/helm-charts/releases/download/kube-prometheus-stack-16.12.0/kube-prometheus-stack-16.12.0.tgz
    valuesSecretRef:
      name: kubes
</code></pre>
<p> </p>

<p>You can use the <a href="https://github.com/pytimer/k8sutil" rel="nofollow noreferrer">k8sutil</a> repo, see the <a href="https://github.com/pytimer/k8sutil/tree/main/examples/apply" rel="nofollow noreferrer">apply</a> example:</p>
<pre><code>package main

import (
    &quot;context&quot;
    &quot;flag&quot;
    &quot;log&quot;
    &quot;path/filepath&quot;

    &quot;github.com/pytimer/k8sutil/apply&quot;

    &quot;k8s.io/client-go/discovery&quot;
    &quot;k8s.io/client-go/dynamic&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
    &quot;k8s.io/client-go/util/homedir&quot;
)

const applyStr = `
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  ports:
  - name: web
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
`

func main() {
    var kubeconfig *string
    if home := homedir.HomeDir(); home != &quot;&quot; {
        kubeconfig = flag.String(&quot;kubeconfig&quot;, filepath.Join(home, &quot;.kube&quot;, &quot;config&quot;), &quot;(optional) absolute path to the kubeconfig file&quot;)
    } else {
        kubeconfig = flag.String(&quot;kubeconfig&quot;, &quot;&quot;, &quot;absolute path to the kubeconfig file&quot;)
    }
    flag.Parse()

    // use the current context in kubeconfig
    config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, *kubeconfig)
    if err != nil {
        panic(err.Error())
    }

    dynamicClient, err := dynamic.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
    discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
    if err != nil {
        panic(err.Error())
    }

    applyOptions := apply.NewApplyOptions(dynamicClient, discoveryClient)
    if err := applyOptions.Apply(context.TODO(), []byte(applyStr)); err != nil {
        log.Fatalf(&quot;apply error: %v&quot;, err)
    }
}
</code></pre>
