github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/pkg/kubernetes/resources/ambassador/module/adapt.go (about) 1 package module 2 3 import ( 4 "github.com/caos/orbos/pkg/kubernetes" 5 "github.com/caos/orbos/pkg/kubernetes/resources" 6 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 7 ) 8 9 type Config struct { 10 EnableGrpcWeb bool 11 } 12 13 const ( 14 group = "getambassador.io" 15 version = "v2" 16 kind = "Module" 17 ) 18 19 func AdaptFuncToEnsure(namespace, name string, labels map[string]string, config *Config) (resources.QueryFunc, error) { 20 spec := map[string]interface{}{} 21 if config != nil { 22 specConfig := map[string]interface{}{} 23 if config.EnableGrpcWeb { 24 specConfig["enable_grpc_web"] = config.EnableGrpcWeb 25 } 26 spec["config"] = specConfig 27 } 28 29 crd := &unstructured.Unstructured{ 30 Object: map[string]interface{}{ 31 "kind": kind, 32 "apiVersion": group + "/" + version, 33 "metadata": map[string]interface{}{ 34 "name": name, 35 "namespace": namespace, 36 "labels": labels, 37 }, 38 "spec": spec, 39 }} 40 41 return func(k8sClient kubernetes.ClientInt, _ map[string]interface{}) (resources.EnsureFunc, error) { 42 return func(k8sClient kubernetes.ClientInt) error { 43 return k8sClient.ApplyNamespacedCRDResource(group, version, kind, namespace, name, crd) 44 }, nil 45 }, nil 46 } 47 48 func AdaptFuncToDestroy(namespace, name string) (resources.DestroyFunc, error) { 49 return func(client kubernetes.ClientInt) error { 50 return client.DeleteNamespacedCRDResource(group, version, kind, namespace, name) 51 }, nil 52 }