func pathForResourceWithName(name, namespace string, gvr schema.GroupVersionResource) string {
	segments := []string{"/apis"}
	if gvr.Group == "" {
		segments = []string{"/api", gvr.Version}
	} else {
		segments = append(segments, gvr.Group, gvr.Version)
	}
	if namespace != "" {
		segments = append(segments, "namespaces", namespace)
	}
	if gvr.Resource != "" {  
		segments = append(segments, gvr.Resource)
	}
	if name != "" {
		segments = append(segments, name)
	}
	return path.Join(segments...)
}
pathForResourceWithName is same as pathForResource but with name segment.
package main
import (
	"bytes"
	"context"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path"
	"strings"
	"github.com/gogo/protobuf/jsonpb"
	gogo_proto "github.com/gogo/protobuf/proto"
	"github.com/golang/protobuf/proto"
	yaml "gopkg.in/yaml.v2"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/client-go/discovery"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/restmapper"
	"k8s.io/client-go/tools/clientcmd"
	_ "k8s.io/api/apps/v1"
	_ "k8s.io/api/batch/v1"
	_ "k8s.io/api/core/v1"
	_ "k8s.io/api/storage/v1"
	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
	"github.com/stripe/skycfg"
	"github.com/stripe/skycfg/gogocompat"
)
var (
	dryRun     = flag.Bool("dry_run", false, "Print objects rendered by Skycfg and don't do anything.")
	namespace  = flag.String("namespace", "default", "Namespace to create/delete objects in.")
	configPath = flag.String("kubeconfig", os.Getenv("HOME")+"/.kube/config", "Kubernetes client config path.")
)
var k8sProtoMagic = []byte("k8s\x00")
func marshal(msg proto.Message) ([]byte, error) {
	msgBytes, err := proto.Marshal(msg)
	if err != nil {
		return nil, err
	}
	unknownBytes, err := proto.Marshal(&runtime.Unknown{Raw: msgBytes})
	if err != nil {
		return nil, err
	}
	return append(k8sProtoMagic, unknownBytes...), nil
}
func pathForResource(namespace string, gvr schema.GroupVersionResource) string {
	return pathForResourceWithName("", namespace, gvr)
}