github.com/verrazzano/verrazzano@v1.7.1/tools/oam-converter/pkg/resources/workloads/virtualservice.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package workloads 5 6 import ( 7 vzapi "github.com/verrazzano/verrazzano/application-operator/apis/oam/v1alpha1" 8 consts "github.com/verrazzano/verrazzano/tools/oam-converter/pkg/constants" 9 vs "github.com/verrazzano/verrazzano/tools/oam-converter/pkg/resources/virtualservice" 10 istio "istio.io/api/networking/v1beta1" 11 vsapi "istio.io/client-go/pkg/apis/networking/v1beta1" 12 corev1 "k8s.io/api/core/v1" 13 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 14 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 15 ) 16 17 func createVirtualServiceFromWorkload(appNamespace string, rule vzapi.IngressRule, 18 allHostsForTrait []string, name string, gateway *vsapi.Gateway, helidonWorkload *unstructured.Unstructured, service *corev1.Service) (*vsapi.VirtualService, error) { 19 virtualService := &vsapi.VirtualService{ 20 TypeMeta: metav1.TypeMeta{ 21 APIVersion: consts.VirtualServiceAPIVersion, 22 Kind: "VirtualService", 23 }, 24 ObjectMeta: metav1.ObjectMeta{ 25 Namespace: appNamespace, 26 Name: name, 27 }, 28 } 29 return mutateVirtualServiceFromWorkload(virtualService, rule, allHostsForTrait, gateway, helidonWorkload, service) 30 } 31 32 // mutateVirtualService mutates the output virtual service resource 33 func mutateVirtualServiceFromWorkload(virtualService *vsapi.VirtualService, rule vzapi.IngressRule, allHostsForTrait []string, gateway *vsapi.Gateway, helidonWorkload *unstructured.Unstructured, service *corev1.Service) (*vsapi.VirtualService, error) { 34 virtualService.Spec.Gateways = []string{gateway.Name} 35 virtualService.Spec.Hosts = allHostsForTrait 36 matches := []*istio.HTTPMatchRequest{} 37 paths := vs.GetPathsFromRule(rule) 38 for _, path := range paths { 39 matches = append(matches, &istio.HTTPMatchRequest{ 40 Uri: vs.CreateVirtualServiceMatchURIFromIngressTraitPath(path)}) 41 } 42 dest, err := createDestinationFromRuleOrService(rule, helidonWorkload, service) 43 if err != nil { 44 print(err) 45 return nil, err 46 } 47 route := istio.HTTPRoute{ 48 Match: matches, 49 Route: []*istio.HTTPRouteDestination{dest}} 50 virtualService.Spec.Http = []*istio.HTTPRoute{&route} 51 52 return virtualService, nil 53 }