diff --git a/istioctl/cmd/istioctl/convert/cmd.go b/istioctl/cmd/istioctl/convert/cmd.go deleted file mode 100644 index dfbf74f6763f..000000000000 --- a/istioctl/cmd/istioctl/convert/cmd.go +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright 2017 Istio Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "os" - - "github.com/ghodss/yaml" - multierror "github.com/hashicorp/go-multierror" - "github.com/spf13/cobra" - "k8s.io/api/extensions/v1beta1" - - "istio.io/istio/istioctl/pkg/convert" - "istio.io/istio/pilot/pkg/config/kube/crd" - "istio.io/istio/pilot/pkg/model" - "istio.io/istio/pkg/log" -) - -var ( - inFilenames []string - outFilename string -) - -// Command for converting v1alpha1 configs to v1alpha3 -func Command() *cobra.Command { - cmd := &cobra.Command{ - Use: "convert-networking-config", - Short: "Convert networking configs from v1alpha1 to v1alpha3", - Long: "Converts sets of v1alpha1 configs to v1alpha3 equivalents on a best effort basis. " + - "The output should be considered a starting point for your v1alpha3 configs and probably " + - "require some minor modification. " + - "Warnings will (hopefully) be generated where configs cannot be converted perfectly, " + - "or in certain edge cases. " + - "The input must be the set of configs that would be in place in an environment at a given " + - "time. " + - "This allows the command to attempt to create and merge output configs intelligently." + - "Output configs are given the namespace and domain of the first input config " + - "so it is recommended that input configs be part of the same namespace and domain.", - Example: "istioctl experimental convert-networking-config -f v1alpha1/default-route.yaml -f v1alpha1/header-delay.yaml", - RunE: func(c *cobra.Command, args []string) error { - if len(inFilenames) == 0 { - return fmt.Errorf("no input files provided") - } - - readers := make([]io.Reader, 0) - if len(inFilenames) == 1 && inFilenames[0] == "-" { - readers = append(readers, os.Stdin) - } else { - for _, filename := range inFilenames { - file, err := os.Open(filename) - if err != nil { - return err - } - defer func() { - if err := file.Close(); err != nil { - log.Errorf("Did not close input %s successfully: %v", - filename, err) - } - }() - readers = append(readers, file) - } - } - - writer := os.Stdout - if outFilename != "-" { - file, err := os.Create(outFilename) - if err != nil { - return err - } - defer func() { - if err := file.Close(); err != nil { - log.Errorf("Did not close output successfully: %v", err) - } - }() - - writer = file - } - - return convertConfigs(readers, writer) - }, - } - - cmd.PersistentFlags().StringSliceVarP(&inFilenames, "filenames", "f", - nil, "Input filenames") - cmd.PersistentFlags().StringVarP(&outFilename, "output", "o", - "-", "Output filename") - - return cmd -} - -func convertConfigs(readers []io.Reader, writer io.Writer) error { - configDescriptor := model.ConfigDescriptor{ - model.RouteRule, - model.VirtualService, - model.Gateway, - model.EgressRule, - model.ServiceEntry, - model.DestinationPolicy, - model.DestinationRule, - model.HTTPAPISpec, - model.HTTPAPISpecBinding, - model.QuotaSpec, - model.QuotaSpecBinding, - } - - configs, ingresses, err := readConfigs(readers) - if err != nil { - return err - } - - if err = validateConfigs(configs); err != nil { - return err - } - - out := make([]model.Config, 0) - out = append(out, convert.DestinationPolicies(configs)...) - out = append(out, convert.RouteRules(configs)...) - out = append(out, convert.EgressRules(configs)...) - convertedIngresses, err := convert.IstioIngresses(ingresses, "") - if err == nil { - out = append(out, convertedIngresses...) - } else { - return multierror.Prefix(err, "Ingress rules invalid") - } - out = append(out, convert.RouteRuleRouteLabels(out, configs)...) - - writeYAMLOutput(configDescriptor, out, writer) - - // sanity check that the outputs are valid - if err := validateConfigs(out); err != nil { - return multierror.Prefix(err, "output config(s) are invalid:") - } - return nil -} - -func readConfigs(readers []io.Reader) ([]model.Config, []*v1beta1.Ingress, error) { - out := make([]model.Config, 0) - outIngresses := make([]*v1beta1.Ingress, 0) - - for _, reader := range readers { - data, err := ioutil.ReadAll(reader) - if err != nil { - return nil, nil, err - } - - configs, kinds, err := crd.ParseInputs(string(data)) - if err != nil { - return nil, nil, err - } - - recognized := 0 - for _, nonIstio := range kinds { - if nonIstio.Kind == "Ingress" && - nonIstio.APIVersion == "extensions/v1beta1" { - - ingress, err := parseIngress(nonIstio) - if err != nil { - log.Errorf("Could not decode ingress %v: %v", nonIstio.Name, err) - continue - } - - outIngresses = append(outIngresses, ingress) - recognized++ - } - } - - if len(kinds) > recognized { - // If convert-networking-config was asked to convert non-network things, - // like Deployments and Services, return a brief informative error - kindsFound := make(map[string]bool) - for _, kind := range kinds { - kindsFound[kind.Kind] = true - } - - var msg error - for kind := range kindsFound { - msg = multierror.Append(msg, fmt.Errorf("unsupported kind: %v", kind)) - } - - return nil, nil, msg - } - - out = append(out, configs...) - } - return out, outIngresses, nil -} - -func writeYAMLOutput(descriptor model.ConfigDescriptor, configs []model.Config, writer io.Writer) { - for i, config := range configs { - schema, exists := descriptor.GetByType(config.Type) - if !exists { - log.Errorf("Unknown kind %q for %v", crd.ResourceName(config.Type), config.Name) - continue - } - obj, err := crd.ConvertConfig(schema, config) - if err != nil { - log.Errorf("Could not decode %v: %v", config.Name, err) - continue - } - bytes, err := yaml.Marshal(obj) - if err != nil { - log.Errorf("Could not convert %v to YAML: %v", config, err) - continue - } - writer.Write(bytes) // nolint: errcheck - if i+1 < len(configs) { - writer.Write([]byte("---\n")) // nolint: errcheck - } - } -} - -func validateConfigs(configs []model.Config) error { - var errs error - for _, config := range configs { - var err error - switch config.Type { - case model.RouteRule.Type: - err = model.ValidateRouteRule(config.Name, config.Namespace, config.Spec) - case model.VirtualService.Type: - err = model.ValidateVirtualService(config.Name, config.Namespace, config.Spec) - case model.Gateway.Type: - err = model.ValidateGateway(config.Name, config.Namespace, config.Spec) - case model.EgressRule.Type: - err = model.ValidateEgressRule(config.Name, config.Namespace, config.Spec) - case model.ServiceEntry.Type: - err = model.ValidateServiceEntry(config.Name, config.Namespace, config.Spec) - case model.DestinationPolicy.Type: - err = model.ValidateDestinationPolicy(config.Name, config.Namespace, config.Spec) - case model.DestinationRule.Type: - err = model.ValidateDestinationRule(config.Name, config.Namespace, config.Spec) - } - if err != nil { - errs = multierror.Append(err, errs) - } - } - return errs -} - -func parseIngress(unparsed crd.IstioKind) (*v1beta1.Ingress, error) { - // To convert unparsed to a v1beta1.Ingress Marshal into JSON and Unmarshal back - b, err := json.Marshal(unparsed) - if err != nil { - return nil, multierror.Prefix(err, "can't reserialize Ingress") - } - - out := &v1beta1.Ingress{} - err = json.Unmarshal(b, out) - if err != nil { - return nil, multierror.Prefix(err, "can't deserialize as Ingress") - } - - return out, nil -} diff --git a/istioctl/cmd/istioctl/convert/cmd_test.go b/istioctl/cmd/istioctl/convert/cmd_test.go deleted file mode 100644 index 76788e76abc4..000000000000 --- a/istioctl/cmd/istioctl/convert/cmd_test.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2017 Istio Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "io" - "os" - "testing" - - "istio.io/istio/pilot/test/util" -) - -func TestCommand(t *testing.T) { - tt := []struct { - in []string - out string - }{ - {in: []string{"rule-default-route.yaml"}, - out: "rule-default-route.yaml"}, - - {in: []string{"rule-weighted-route.yaml"}, - out: "rule-weighted-route.yaml"}, - - {in: []string{"rule-default-route.yaml", - "rule-content-route.yaml"}, - out: "rule-content-route.yaml"}, - - {in: []string{"rule-default-route.yaml", - "rule-regex-route.yaml"}, - out: "rule-regex-route.yaml"}, - - {in: []string{"rule-default-route.yaml", - "rule-fault-injection.yaml"}, - out: "rule-fault-injection.yaml"}, - - {in: []string{"rule-default-route.yaml", - "rule-redirect-injection.yaml"}, - out: "rule-redirect-injection.yaml"}, - - {in: []string{"rule-default-route.yaml", - "rule-websocket-route.yaml"}, - out: "rule-websocket-route.yaml"}, - - {in: []string{"rule-default-route-append-headers.yaml"}, - out: "rule-default-route-append-headers.yaml"}, - - {in: []string{"rule-default-route-cors-policy.yaml"}, - out: "rule-default-route-cors-policy.yaml"}, - - {in: []string{"rule-default-route-mirrored.yaml"}, - out: "rule-default-route-mirrored.yaml"}, - - {in: []string{"egress-rule-google.yaml"}, - out: "egress-rule-google.yaml"}, - - {in: []string{"egress-rule-httpbin.yaml"}, - out: "egress-rule-httpbin.yaml"}, - - {in: []string{"egress-rule-tcp-wikipedia-cidr.yaml"}, - out: "egress-rule-tcp-wikipedia-cidr.yaml"}, - - {in: []string{"egress-rule-wildcard-httpbin.yaml"}, - out: "egress-rule-wildcard-httpbin.yaml"}, - - {in: []string{"destination-policy-helloworld.yaml"}, - out: "destination-rule-helloworld.yaml"}, - - {in: []string{"route-rule-80-20.yaml"}, - out: "route-rule-80-20.yaml"}, - - // Verify that we merge rather than duplicate when creating VirtualService+DestinationRule - {in: []string{"route-rule-80-20.yaml", "destination-policy-helloworld.yaml"}, - out: "route-rule-80-20-with-destpolicy.yaml"}, - - // Verify the merging is correct if the rules arrive in a different order - {in: []string{"destination-policy-helloworld.yaml", "route-rule-80-20.yaml"}, - out: "destination-rule-helloworld-with-80-20.yaml"}, - - {in: []string{"nolabel-destination-policy.yaml"}, - out: "nolabel-destination-rule.yaml"}, - - // Verify we can convert Kubernetes Istio Ingress - {in: []string{"myservice-ingress.yaml"}, - out: "myservice-gateway.yaml"}, - - // Verify we can merge Ingresses - {in: []string{"myservice-ingress.yaml", "another-ingress.yaml"}, - out: "merged-gateway.yaml"}, - } - - for _, tc := range tt { - t.Run(tc.out, func(t *testing.T) { - readers := make([]io.Reader, 0, len(tc.in)) - for _, filename := range tc.in { - file, err := os.Open("testdata/v1alpha1/" + filename) - if err != nil { - t.Fatal(err) - } - defer file.Close() // nolint: errcheck - readers = append(readers, file) - } - - outFilename := "testdata/v1alpha3/" + tc.out - out, err := os.Create(outFilename) - if err != nil { - t.Fatal(err) - } - defer out.Close() // nolint: errcheck - - if err := convertConfigs(readers, out); err != nil { - t.Fatalf("Unexpected error converting configs: %v", err) - } - - util.CompareYAML(outFilename, t) - }) - } -} diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/another-ingress.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/another-ingress.yaml deleted file mode 100644 index 5c4f75f5dc68..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/another-ingress.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Ingress -metadata: - annotations: - kubernetes.io/ingress.class: istio - name: another-ingress - namespace: another-namespace -spec: - rules: - - http: - paths: - - path: /foo/bar/ - backend: - serviceName: anotherservice-service - servicePort: 7080 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/destination-policy-helloworld.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/destination-policy-helloworld.yaml deleted file mode 100644 index 9170116b30c7..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/destination-policy-helloworld.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: config.istio.io/v1beta1 -kind: DestinationPolicy -metadata: - name: helloworld-circuit-breaker -spec: - destination: - name: helloworld-service - labels: - version: "1.0" - circuitBreaker: - simpleCb: - maxConnections: 1 - httpMaxPendingRequests: 1 - sleepWindow: 3m - httpDetectionInterval: 1s - httpMaxEjectionPercent: 100 - httpConsecutiveErrors: 1 - httpMaxRequestsPerConnection: 1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-google.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-google.yaml deleted file mode 100644 index 6ed372b00960..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-google.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: EgressRule -metadata: - name: google -spec: - destination: - service: "*google.com" - ports: - - port: 443 - protocol: https - use_egress_proxy: false diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-httpbin.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-httpbin.yaml deleted file mode 100644 index cedb8e206fd4..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-httpbin.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: EgressRule -metadata: - name: httpbin -spec: - destination: - service: "httpbin.org" - ports: - - port: 80 - protocol: http - use_egress_proxy: false diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-tcp-wikipedia-cidr.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-tcp-wikipedia-cidr.yaml deleted file mode 100644 index 29b116f9fefb..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-tcp-wikipedia-cidr.yaml +++ /dev/null @@ -1,61 +0,0 @@ -# wikipedia.org IP addresses, according to https://www.mediawiki.org/wiki/Wikipedia_Zero/IP_Addresses -# 91.198.174.192/27 -# 103.102.166.224/27 -# 198.35.26.96/27 -# 208.80.153.224/27 -# 208.80.154.224/27 - -kind: EgressRule -metadata: - name: wikipedia-range1 -spec: - destination: - service: 91.198.174.192/27 - ports: - - port: 443 - protocol: tcp - use_egress_proxy: false ---- -kind: EgressRule -metadata: - name: wikipedia-range2 -spec: - destination: - service: 103.102.166.224/27 - ports: - - port: 443 - protocol: tcp - use_egress_proxy: false ---- -kind: EgressRule -metadata: - name: wikipedia-range3 -spec: - destination: - service: 198.35.26.96/27 - ports: - - port: 443 - protocol: tcp - use_egress_proxy: false ---- -kind: EgressRule -metadata: - name: wikipedia-range4 -spec: - destination: - service: 208.80.153.224/27 - ports: - - port: 443 - protocol: tcp - use_egress_proxy: false ---- -kind: EgressRule -metadata: - name: wikipedia-range5 -spec: - destination: - service: 208.80.154.224/27 - ports: - - port: 443 - protocol: tcp - use_egress_proxy: false diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-wildcard-httpbin.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-wildcard-httpbin.yaml deleted file mode 100644 index ad31eb98a3c8..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/egress-rule-wildcard-httpbin.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: EgressRule -metadata: - name: httpbin-wildcard -spec: - destination: - service: "*.httpbin.org" - ports: - - port: 80 - protocol: http - use_egress_proxy: false diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/myservice-ingress.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/myservice-ingress.yaml deleted file mode 100644 index 4ad0bf4d5206..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/myservice-ingress.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Ingress -metadata: - annotations: - kubernetes.io/ingress.class: istio - name: simple-ingress - namespace: default -spec: - rules: - - http: - paths: - - path: /foo/.* - backend: - serviceName: myservice-service - servicePort: 9080 - - path: /.* - backend: - serviceName: my-ui - servicePort: 80 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/nolabel-destination-policy.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/nolabel-destination-policy.yaml deleted file mode 100644 index cbf2fd8ad4a1..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/nolabel-destination-policy.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: config.istio.io/v1beta1 -kind: DestinationPolicy -metadata: - name: helloworld-circuit-breaker -spec: - destination: - name: alpha-service - circuitBreaker: - simpleCb: - maxConnections: 64 - httpMaxPendingRequests: 16 - sleepWindow: 1m - httpDetectionInterval: 10s - httpMaxEjectionPercent: 100 - httpConsecutiveErrors: 2 - httpMaxRequestsPerConnection: 2 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/route-rule-80-20.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/route-rule-80-20.yaml deleted file mode 100644 index c3d603e00d67..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/route-rule-80-20.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: route-rule-80-20 -spec: - destination: - name: helloworld-service - precedence: 1 - route: - - labels: - version: "1.0" - weight: 80 - - labels: - version: "2.0" - weight: 20 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-content-route.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-content-route.yaml deleted file mode 100644 index ba69e8b99d9f..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-content-route.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: content-route -spec: - destination: - name: c - precedence: 2 - match: - source: - name: a - labels: - version: v1 - request: - headers: - version: - exact: v2 - route: - - labels: - version: v2 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-append-headers.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-append-headers.yaml deleted file mode 100644 index 3fb162c5414d..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-append-headers.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: default-route -spec: - destination: - name: c - precedence: 1 - route: - - labels: - version: v1 - weight: 100 - appendHeaders: - istio-custom-header: user-defined-value diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-cors-policy.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-cors-policy.yaml deleted file mode 100644 index 8c5515302dbe..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-cors-policy.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: default-route -spec: - destination: - name: c - precedence: 1 - route: - - labels: - version: v1 - weight: 100 - corsPolicy: - allowOrigin: - - http://foo.example - allowMethods: - - POST - - GET - - OPTIONS - allowHeaders: - - content-type - exposeHeaders: - - x-custom-header - maxAge: 300s - allowCredentials: true diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-mirrored.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-mirrored.yaml deleted file mode 100644 index 0ac4325bcd20..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route-mirrored.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: default-route -spec: - destination: - name: c - precedence: 1 - mirror: - name: b diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route.yaml deleted file mode 100644 index 359a6266c009..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-default-route.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: default-route -spec: - destination: - name: c - precedence: 1 - route: - - labels: - version: v1 - weight: 100 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-fault-injection.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-fault-injection.yaml deleted file mode 100644 index 1e9ad364bc2b..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-fault-injection.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: fault-route -spec: - destination: - name: c - precedence: 3 - match: - source: - name: a - labels: - version: v1 - request: - headers: - version: - exact: v2 - route: - - labels: - version: v2 - httpFault: - delay: - percent: 100 - fixedDelay: 5s - abort: - percent: 100 - httpStatus: 503 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-redirect-injection.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-redirect-injection.yaml deleted file mode 100644 index fc16b47d1dfc..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-redirect-injection.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: redirect-route -spec: - destination: - name: c - precedence: 5 - match: - request: - headers: - testredirect: - exact: enabled - redirect: - uri: /new/path - authority: b diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-regex-route.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-regex-route.yaml deleted file mode 100644 index 8497d2d526a9..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-regex-route.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: content-route -spec: - destination: - name: c - precedence: 4 - match: - source: - name: a - labels: - version: v1 - request: - headers: - foo: - regex: "b.*" - route: - - labels: - version: v2 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-websocket-route.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-websocket-route.yaml deleted file mode 100644 index 986622543502..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-websocket-route.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: websocket-route -spec: - destination: - name: c - precedence: 6 - match: - request: - headers: - testwebsocket: - exact: enabled - route: - - labels: - version: v1 - websocketUpgrade: true diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-weighted-route.yaml b/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-weighted-route.yaml deleted file mode 100644 index cae4a81badd5..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha1/rule-weighted-route.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: config.istio.io/v1alpha2 -kind: RouteRule -metadata: - name: default-route -spec: - destination: - name: c - precedence: 1 - route: - - labels: - version: v1 - weight: 75 - - labels: - version: v2 - weight: 25 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/.gitignore b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/.gitignore deleted file mode 100644 index 1e82fc7debc1..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.yaml diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/destination-rule-helloworld-with-80-20.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/destination-rule-helloworld-with-80-20.yaml.golden deleted file mode 100644 index 20a30f2ae0a5..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/destination-rule-helloworld-with-80-20.yaml.golden +++ /dev/null @@ -1,47 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - host: helloworld-service - subsets: - - labels: - version: "1.0" - name: version-1-0 - trafficPolicy: - connectionPool: - http: - http1MaxPendingRequests: 1 - maxRequestsPerConnection: 1 - tcp: - maxConnections: 1 - outlierDetection: - baseEjectionTime: 180.000s - consecutiveErrors: 1 - interval: 1.000s - maxEjectionPercent: 100 - - labels: - version: "2.0" - name: version-2-0 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - hosts: - - helloworld-service - http: - - route: - - destination: - host: helloworld-service - subset: version-1-0 - weight: 80 - - destination: - host: helloworld-service - subset: version-2-0 - weight: 20 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/destination-rule-helloworld.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/destination-rule-helloworld.yaml.golden deleted file mode 100644 index 50993dd8909f..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/destination-rule-helloworld.yaml.golden +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - host: helloworld-service - subsets: - - labels: - version: "1.0" - name: version-1-0 - trafficPolicy: - connectionPool: - http: - http1MaxPendingRequests: 1 - maxRequestsPerConnection: 1 - tcp: - maxConnections: 1 - outlierDetection: - baseEjectionTime: 180.000s - consecutiveErrors: 1 - interval: 1.000s - maxEjectionPercent: 100 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-google.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-google.yaml.golden deleted file mode 100644 index c7e35d4792b1..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-google.yaml.golden +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: google - namespace: default -spec: - hosts: - - '*google.com' - ports: - - name: https-443 - number: 443 - protocol: https diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-httpbin.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-httpbin.yaml.golden deleted file mode 100644 index 36d99980f422..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-httpbin.yaml.golden +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: httpbin - namespace: default -spec: - hosts: - - httpbin.org - ports: - - name: http-80 - number: 80 - protocol: http diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-tcp-wikipedia-cidr.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-tcp-wikipedia-cidr.yaml.golden deleted file mode 100644 index 57eab179e789..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-tcp-wikipedia-cidr.yaml.golden +++ /dev/null @@ -1,79 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: wikipedia-range1 - namespace: default -spec: - addresses: - - 91.198.174.192/27 - hosts: - - wikipedia-range1.default.svc.cluster.local - ports: - - name: tcp-443 - number: 443 - protocol: tcp ---- -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: wikipedia-range2 - namespace: default -spec: - addresses: - - 103.102.166.224/27 - hosts: - - wikipedia-range2.default.svc.cluster.local - ports: - - name: tcp-443 - number: 443 - protocol: tcp ---- -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: wikipedia-range3 - namespace: default -spec: - addresses: - - 198.35.26.96/27 - hosts: - - wikipedia-range3.default.svc.cluster.local - ports: - - name: tcp-443 - number: 443 - protocol: tcp ---- -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: wikipedia-range4 - namespace: default -spec: - addresses: - - 208.80.153.224/27 - hosts: - - wikipedia-range4.default.svc.cluster.local - ports: - - name: tcp-443 - number: 443 - protocol: tcp ---- -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: wikipedia-range5 - namespace: default -spec: - addresses: - - 208.80.154.224/27 - hosts: - - wikipedia-range5.default.svc.cluster.local - ports: - - name: tcp-443 - number: 443 - protocol: tcp diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-wildcard-httpbin.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-wildcard-httpbin.yaml.golden deleted file mode 100644 index f1c42bb1040d..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/egress-rule-wildcard-httpbin.yaml.golden +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - creationTimestamp: null - name: httpbin-wildcard - namespace: default -spec: - hosts: - - '*.httpbin.org' - ports: - - name: http-80 - number: 80 - protocol: http diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/merged-gateway.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/merged-gateway.yaml.golden deleted file mode 100644 index 496d2dfa99fe..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/merged-gateway.yaml.golden +++ /dev/null @@ -1,69 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: Gateway -metadata: - creationTimestamp: null - name: istio-autogenerated-k8s-ingress - namespace: default -spec: - selector: - istio: ingressgateway - servers: - - hosts: - - '*' - port: - name: http-80-ingress-simple-ingress-default - number: 80 - protocol: HTTP ---- -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: simple-ingress-istio-autogenerated-k8s-ingress - namespace: default -spec: - gateways: - - istio-autogenerated-k8s-ingress - hosts: - - '*' - http: - - match: - - uri: - prefix: /foo/ - route: - - destination: - host: myservice-service.default.svc.cluster.local - port: - number: 9080 - weight: 100 - - match: - - uri: - prefix: / - route: - - destination: - host: my-ui.default.svc.cluster.local - port: - number: 80 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: another-ingress-istio-autogenerated-k8s-ingress - namespace: another-namespace -spec: - gateways: - - istio-autogenerated-k8s-ingress - hosts: - - '*' - http: - - match: - - uri: - exact: /foo/bar/ - route: - - destination: - host: anotherservice-service.another-namespace.svc.cluster.local - port: - number: 7080 - weight: 100 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/myservice-gateway.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/myservice-gateway.yaml.golden deleted file mode 100644 index ae4ce2a7b878..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/myservice-gateway.yaml.golden +++ /dev/null @@ -1,47 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: Gateway -metadata: - creationTimestamp: null - name: istio-autogenerated-k8s-ingress - namespace: default -spec: - selector: - istio: ingressgateway - servers: - - hosts: - - '*' - port: - name: http-80-ingress-simple-ingress-default - number: 80 - protocol: HTTP ---- -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: simple-ingress-istio-autogenerated-k8s-ingress - namespace: default -spec: - gateways: - - istio-autogenerated-k8s-ingress - hosts: - - '*' - http: - - match: - - uri: - prefix: /foo/ - route: - - destination: - host: myservice-service.default.svc.cluster.local - port: - number: 9080 - weight: 100 - - match: - - uri: - prefix: / - route: - - destination: - host: my-ui.default.svc.cluster.local - port: - number: 80 - weight: 100 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/nolabel-destination-rule.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/nolabel-destination-rule.yaml.golden deleted file mode 100644 index 34cbdb44f23e..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/nolabel-destination-rule.yaml.golden +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: alpha-service - namespace: default -spec: - host: alpha-service - subsets: - - name: default - trafficPolicy: - connectionPool: - http: - http1MaxPendingRequests: 16 - maxRequestsPerConnection: 2 - tcp: - maxConnections: 64 - outlierDetection: - baseEjectionTime: 60.000s - consecutiveErrors: 2 - interval: 10.000s - maxEjectionPercent: 100 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/route-rule-80-20-with-destpolicy.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/route-rule-80-20-with-destpolicy.yaml.golden deleted file mode 100644 index 20a30f2ae0a5..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/route-rule-80-20-with-destpolicy.yaml.golden +++ /dev/null @@ -1,47 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - host: helloworld-service - subsets: - - labels: - version: "1.0" - name: version-1-0 - trafficPolicy: - connectionPool: - http: - http1MaxPendingRequests: 1 - maxRequestsPerConnection: 1 - tcp: - maxConnections: 1 - outlierDetection: - baseEjectionTime: 180.000s - consecutiveErrors: 1 - interval: 1.000s - maxEjectionPercent: 100 - - labels: - version: "2.0" - name: version-2-0 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - hosts: - - helloworld-service - http: - - route: - - destination: - host: helloworld-service - subset: version-1-0 - weight: 80 - - destination: - host: helloworld-service - subset: version-2-0 - weight: 20 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/route-rule-80-20.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/route-rule-80-20.yaml.golden deleted file mode 100644 index dbec24ee2b6e..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/route-rule-80-20.yaml.golden +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - hosts: - - helloworld-service - http: - - route: - - destination: - host: helloworld-service - subset: version-1-0 - weight: 80 - - destination: - host: helloworld-service - subset: version-2-0 - weight: 20 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: helloworld-service - namespace: default -spec: - host: helloworld-service - subsets: - - labels: - version: "1.0" - name: version-1-0 - - labels: - version: "2.0" - name: version-2-0 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-content-route.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-content-route.yaml.golden deleted file mode 100644 index 8c78842cd0e3..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-content-route.yaml.golden +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - match: - - headers: - version: - exact: v2 - route: - - destination: - host: c - subset: version-v2 - - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v2 - name: version-v2 - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-append-headers.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-append-headers.yaml.golden deleted file mode 100644 index b4946a94c6fb..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-append-headers.yaml.golden +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - appendHeaders: - istio-custom-header: user-defined-value - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-cors-policy.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-cors-policy.yaml.golden deleted file mode 100644 index 732e2befba8b..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-cors-policy.yaml.golden +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - corsPolicy: - allowCredentials: true - allowHeaders: - - content-type - allowMethods: - - POST - - GET - - OPTIONS - allowOrigin: - - http://foo.example - exposeHeaders: - - x-custom-header - maxAge: 300.000s - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-mirrored.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-mirrored.yaml.golden deleted file mode 100644 index 9f9c28092fc5..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route-mirrored.yaml.golden +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - mirror: - host: b - route: - - destination: - host: c - weight: 100 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route.yaml.golden deleted file mode 100644 index f9f26df51036..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-default-route.yaml.golden +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-fault-injection.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-fault-injection.yaml.golden deleted file mode 100644 index b9b97f3a6c00..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-fault-injection.yaml.golden +++ /dev/null @@ -1,46 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - fault: - abort: - httpStatus: 503 - percent: 100 - delay: - fixedDelay: 5.000s - percent: 100 - match: - - headers: - version: - exact: v2 - route: - - destination: - host: c - subset: version-v2 - - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v2 - name: version-v2 - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-redirect-injection.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-redirect-injection.yaml.golden deleted file mode 100644 index fa8d4a407d7e..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-redirect-injection.yaml.golden +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - match: - - headers: - testredirect: - exact: enabled - redirect: - authority: b - uri: /new/path - - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-regex-route.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-regex-route.yaml.golden deleted file mode 100644 index fa6707b42c2e..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-regex-route.yaml.golden +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - match: - - headers: - foo: - regex: b.* - route: - - destination: - host: c - subset: version-v2 - - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v2 - name: version-v2 - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-websocket-route.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-websocket-route.yaml.golden deleted file mode 100644 index 08e723ef3782..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-websocket-route.yaml.golden +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - match: - - headers: - testwebsocket: - exact: enabled - route: - - destination: - host: c - subset: version-v1 - websocketUpgrade: true - - route: - - destination: - host: c - subset: version-v1 - weight: 100 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v1 - name: version-v1 diff --git a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-weighted-route.yaml.golden b/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-weighted-route.yaml.golden deleted file mode 100644 index 5b2a99616cf3..000000000000 --- a/istioctl/cmd/istioctl/convert/testdata/v1alpha3/rule-weighted-route.yaml.golden +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: networking.istio.io/v1alpha3 -kind: VirtualService -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - hosts: - - c - http: - - route: - - destination: - host: c - subset: version-v1 - weight: 75 - - destination: - host: c - subset: version-v2 - weight: 25 ---- -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule -metadata: - creationTimestamp: null - name: c - namespace: default -spec: - host: c - subsets: - - labels: - version: v1 - name: version-v1 - - labels: - version: v2 - name: version-v2 diff --git a/istioctl/cmd/istioctl/istioctl_test.go b/istioctl/cmd/istioctl/istioctl_test.go index f85cec0854cc..87e0a93ebe48 100644 --- a/istioctl/cmd/istioctl/istioctl_test.go +++ b/istioctl/cmd/istioctl/istioctl_test.go @@ -319,24 +319,12 @@ googleapis *.googleapis.com HTTP/443 default func TestCreate(t *testing.T) { cases := []testCase{ - { // case 0 -- invalid doesn't provide -f filename + { // invalid doesn't provide -f filename configs: []model.Config{}, args: strings.Split("create routerules", " "), expectedRegexp: regexp.MustCompile("^Usage:.*"), wantException: true, }, - { // case 1 - configs: []model.Config{}, - args: strings.Split("create -f convert/testdata/v1alpha1/route-rule-80-20.yaml", " "), - expectedRegexp: regexp.MustCompile("^Warning: route-rule is deprecated and will not be supported" + - " in future Istio versions \\(route-rule-80-20\\).\n" + - "Created config route-rule/default/route-rule-80-20.*"), - }, - { // case 2 - configs: []model.Config{}, - args: strings.Split("create -f convert/testdata/v1alpha3/route-rule-80-20.yaml.golden", " "), - expectedRegexp: regexp.MustCompile("^Created config virtual-service/default/helloworld-service.*"), - }, } for i, c := range cases { @@ -384,13 +372,7 @@ func TestDelete(t *testing.T) { Deleted config: routerule b `, }, - { // case 3 - delete by filename of istio config which doesn't exist - configs: testRouteRules, - args: strings.Split("delete -f convert/testdata/v1alpha1/route-rule-80-20.yaml", " "), - expectedRegexp: regexp.MustCompile("^Error: 1 error occurred:\n\n\\* cannot delete route-rule/default/route-rule-80-20: item not found\n$"), - wantException: true, - }, - { // case 4 - "all" not valid for delete + { // case 3 - "all" not valid for delete configs: []model.Config{}, args: strings.Split("delete all foo", " "), expectedRegexp: regexp.MustCompile("^Error: configuration type all not found"), diff --git a/istioctl/cmd/istioctl/main.go b/istioctl/cmd/istioctl/main.go index 274e02e1bd1b..c65a04d5b83e 100644 --- a/istioctl/cmd/istioctl/main.go +++ b/istioctl/cmd/istioctl/main.go @@ -45,7 +45,6 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "istio.io/api/networking/v1alpha3" - "istio.io/istio/istioctl/cmd/istioctl/convert" "istio.io/istio/istioctl/cmd/istioctl/gendeployment" "istio.io/istio/pilot/pkg/config/kube/crd" "istio.io/istio/pilot/pkg/model" @@ -658,7 +657,6 @@ func init() { "If present, list the requested object(s) across all namespaces. Namespace in current "+ "context is ignored even if specified with --namespace.") - experimentalCmd.AddCommand(convert.Command()) experimentalCmd.AddCommand(Rbac()) // Attach the Istio logging options to the command. diff --git a/istioctl/pkg/convert/destination.go b/istioctl/pkg/convert/destination.go deleted file mode 100644 index a458608a80e8..000000000000 --- a/istioctl/pkg/convert/destination.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2017 Istio Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "istio.io/api/networking/v1alpha3" - "istio.io/api/routing/v1alpha1" - "istio.io/istio/pilot/pkg/model" - "istio.io/istio/pkg/log" -) - -// DestinationPolicies converts v1alpha1 destination policies to v1alpha3 destination rules -func DestinationPolicies(configs []model.Config) []model.Config { - policies := make([]*v1alpha1.DestinationPolicy, 0) - for _, config := range configs { - if config.Type == model.DestinationPolicy.Type { - policies = append(policies, config.Spec.(*v1alpha1.DestinationPolicy)) - } - } - - destinationRules := make(map[string]*v1alpha3.DestinationRule) // host -> destination rule - for _, policy := range policies { - host := convertIstioService(policy.Destination) - if destinationRules[host] == nil { - destinationRules[host] = &v1alpha3.DestinationRule{Host: host} - } - destinationRule := destinationRules[host] - destinationRule.Subsets = append(destinationRule.Subsets, convertDestinationPolicy(policy)) - } - - out := make([]model.Config, 0) - for host, rule := range destinationRules { - out = append(out, model.Config{ - ConfigMeta: model.ConfigMeta{ - Type: model.DestinationRule.Type, - Name: host, - Namespace: configs[0].Namespace, - Domain: configs[0].Domain, - }, - Spec: rule, - }) - } - - return out -} - -func convertLoadBalancing(in *v1alpha1.LoadBalancing) *v1alpha3.LoadBalancerSettings { - if in == nil { - return nil - } - - switch v := in.LbPolicy.(type) { - case *v1alpha1.LoadBalancing_Custom: - log.Warnf("Custom load balancing not supported") - case *v1alpha1.LoadBalancing_Name: - simple := &v1alpha3.LoadBalancerSettings_Simple{} - switch v.Name { - case v1alpha1.LoadBalancing_ROUND_ROBIN: - simple.Simple = v1alpha3.LoadBalancerSettings_ROUND_ROBIN - case v1alpha1.LoadBalancing_LEAST_CONN: - simple.Simple = v1alpha3.LoadBalancerSettings_LEAST_CONN - case v1alpha1.LoadBalancing_RANDOM: - simple.Simple = v1alpha3.LoadBalancerSettings_RANDOM - } - return &v1alpha3.LoadBalancerSettings{ - LbPolicy: simple, - } - } - return nil -} - -func convertDestinationPolicy(in *v1alpha1.DestinationPolicy) *v1alpha3.Subset { - if in == nil { - return nil - } - - out := &v1alpha3.Subset{ - Name: labelsToSubsetName(in.Destination.Labels), - Labels: in.Destination.Labels, - TrafficPolicy: &v1alpha3.TrafficPolicy{ - LoadBalancer: convertLoadBalancing(in.LoadBalancing), - }, - } - - // We can't have an unnamed subset - if out.Name == "" { - out.Name = "default" - } - - // TODO: in.Source - if in.Source != nil { - log.Warnf("Destination policy source not supported") - } - - if in.CircuitBreaker != nil { - if in.CircuitBreaker.GetCustom() != nil { - log.Warnf("Custom circuit breaker policy not supported") - } - - if cb := in.CircuitBreaker.GetSimpleCb(); cb != nil { - out.TrafficPolicy.ConnectionPool = &v1alpha3.ConnectionPoolSettings{ - Http: &v1alpha3.ConnectionPoolSettings_HTTPSettings{ - Http2MaxRequests: cb.HttpMaxRequests, - Http1MaxPendingRequests: cb.HttpMaxPendingRequests, - MaxRequestsPerConnection: cb.HttpMaxRequestsPerConnection, - MaxRetries: cb.HttpMaxRetries, - }, - Tcp: &v1alpha3.ConnectionPoolSettings_TCPSettings{ - MaxConnections: cb.MaxConnections, - }, - } - - // TODO: out.TrafficPolicy.ConnectionPool.Tcp.MaxConnections = - out.TrafficPolicy.OutlierDetection = &v1alpha3.OutlierDetection{ - Interval: convertGogoDuration(cb.HttpDetectionInterval), - ConsecutiveErrors: cb.HttpConsecutiveErrors, - BaseEjectionTime: convertGogoDuration(cb.SleepWindow), - MaxEjectionPercent: cb.HttpMaxEjectionPercent, - } - } - } - - if in.Custom != nil { - log.Warn("Custom destination policy not supported") - } - - return out -} diff --git a/istioctl/pkg/convert/egress.go b/istioctl/pkg/convert/egress.go deleted file mode 100644 index 3f1ed02ecb0e..000000000000 --- a/istioctl/pkg/convert/egress.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2017 Istio Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "fmt" - - "istio.io/api/networking/v1alpha3" - "istio.io/api/routing/v1alpha1" - "istio.io/istio/pilot/pkg/model" - "istio.io/istio/pkg/log" -) - -type egressConfig struct { - name string - namespace string - domain string - egressRule *v1alpha1.EgressRule -} - -// EgressRules converts v1alpha1 egress rules to v1alpha3 service entries -func EgressRules(configs []model.Config) []model.Config { - - egressConfigs := make([]egressConfig, 0) - out := make([]model.Config, 0) - for _, config := range configs { - if config.Type == model.EgressRule.Type { - rule := egressConfig{ - name: config.Name, - namespace: config.Namespace, - domain: config.Domain, - egressRule: config.Spec.(*v1alpha1.EgressRule)} - if len(rule.namespace) == 0 { - rule.namespace = "default" - } - - if len(rule.domain) == 0 { - rule.domain = "cluster.local" - } - - egressConfigs = append(egressConfigs, rule) - } - } - - for _, config := range egressConfigs { - host := convertIstioService(config.egressRule.Destination) - var addresses []string - if model.ValidateIPv4Subnet(host) == nil { - addresses = []string{host} - // hosts cannot have short names - host = fmt.Sprintf("%s.%s.svc.%s", config.name, config.namespace, config.domain) - } - - ports := make([]*v1alpha3.Port, 0) - for _, egressPort := range config.egressRule.Ports { - ports = append(ports, &v1alpha3.Port{ - Name: fmt.Sprintf("%s-%d", egressPort.Protocol, egressPort.Port), - Protocol: egressPort.Protocol, - Number: uint32(egressPort.Port), - }) - } - - if config.egressRule.UseEgressProxy { - log.Warnf("Use egress proxy field not supported") - } - - out = append(out, model.Config{ - ConfigMeta: model.ConfigMeta{ - Type: model.ServiceEntry.Type, - Name: config.name, - Namespace: config.namespace, - Domain: config.domain, - }, - Spec: &v1alpha3.ServiceEntry{ - Hosts: []string{host}, - Addresses: addresses, - Ports: ports, - Resolution: v1alpha3.ServiceEntry_NONE, - }, - }) - } - - return out -} diff --git a/istioctl/pkg/convert/ingress.go b/istioctl/pkg/convert/ingress.go deleted file mode 100644 index 688d2e8ba6e5..000000000000 --- a/istioctl/pkg/convert/ingress.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2018 Istio Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "k8s.io/api/extensions/v1beta1" - - networking "istio.io/api/networking/v1alpha3" - "istio.io/istio/pilot/pkg/config/kube/ingress" - "istio.io/istio/pilot/pkg/model" -) - -// IstioIngresses converts K8s extensions/v1beta1 Ingresses with Istio rules to v1alpha3 gateway and virtual service -func IstioIngresses(ingresses []*v1beta1.Ingress, domainSuffix string) ([]model.Config, error) { - - if len(ingresses) == 0 { - return make([]model.Config, 0), nil - } - if len(domainSuffix) == 0 { - domainSuffix = "cluster.local" - } - - gateways := make([]model.Config, 0) - virtualServices := make([]model.Config, 0) - - for _, ingrezz := range ingresses { - gateway, virtualService := ingress.ConvertIngressV1alpha3(*ingrezz, domainSuffix) - // Override the generated namespace; the supplied one is needed to resolve non-fully qualified hosts - gateway.Namespace = ingrezz.Namespace - virtualService.Namespace = ingrezz.Namespace - gateways = append(gateways, gateway) - virtualServices = append(virtualServices, virtualService) - } - - merged := model.MergeGateways(gateways...) - - // Make a list of the servers. Don't attempt any extra merging beyond MergeGateways() impl. - allServers := make([]*networking.Server, 0) - for _, servers := range merged.Servers { - allServers = append(allServers, servers...) - } - - // Convert the merged Gateway back into a model.Config - mergedGateway := model.Config{ - ConfigMeta: gateways[0].ConfigMeta, - Spec: &networking.Gateway{ - Servers: allServers, - Selector: map[string]string{"istio": "ingressgateway"}, - }, - } - - // Fix the name of the gateway - mergedGateway.Name = model.IstioIngressGatewayName - - // Ensure the VirtualServices all point to mergedGateway - for _, virtualService := range virtualServices { - virtualService.Spec.(*networking.VirtualService).Gateways[0] = mergedGateway.ConfigMeta.Name - } - - out := []model.Config{mergedGateway} - out = append(out, virtualServices...) - - return out, nil -} diff --git a/istioctl/pkg/convert/route.go b/istioctl/pkg/convert/route.go deleted file mode 100644 index f1563ad3558f..000000000000 --- a/istioctl/pkg/convert/route.go +++ /dev/null @@ -1,462 +0,0 @@ -// Copyright 2017 Istio Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package convert - -import ( - "strings" - - "github.com/gogo/protobuf/types" - "github.com/golang/protobuf/ptypes/duration" - - "istio.io/api/networking/v1alpha3" - "istio.io/api/routing/v1alpha1" - "istio.io/istio/pilot/pkg/model" - "istio.io/istio/pkg/log" -) - -// RouteRules converts v1alpha1 route rules to v1alpha3 virtual services -func RouteRules(configs []model.Config) []model.Config { - ruleConfigs := make([]model.Config, 0) - for _, config := range configs { - if config.Type == model.RouteRule.Type { - ruleConfigs = append(ruleConfigs, config) - } - } - - model.SortRouteRules(ruleConfigs) - - routeRules := make([]*v1alpha1.RouteRule, 0) - for _, ruleConfig := range ruleConfigs { - routeRules = append(routeRules, ruleConfig.Spec.(*v1alpha1.RouteRule)) - } - - virtualServices := make(map[string]*v1alpha3.VirtualService) // host -> virtual service - for _, routeRule := range routeRules { - host := convertIstioService(routeRule.Destination) - if virtualServices[host] == nil { - virtualServices[host] = &v1alpha3.VirtualService{ - Hosts: []string{host}, - } - } - rule := virtualServices[host] - - rule.Http = append(rule.Http, convertRouteRule(routeRule)) - } - - out := make([]model.Config, 0) - for host, virtualService := range virtualServices { - out = append(out, model.Config{ - ConfigMeta: model.ConfigMeta{ - Type: model.VirtualService.Type, - Name: host, - Namespace: configs[0].Namespace, - Domain: configs[0].Domain, - }, - Spec: virtualService, - }) - } - - return out -} - -func convertRouteRule(in *v1alpha1.RouteRule) *v1alpha3.HTTPRoute { - if in == nil { - return nil - } - - if in.L4Fault != nil { - log.Warn("L4 fault not supported") - } - - return &v1alpha3.HTTPRoute{ - Match: convertMatch(in.Match), - Route: convertRoutes(in), - Redirect: convertRedirect(in.Redirect), - Rewrite: convertRewrite(in.Rewrite), - WebsocketUpgrade: in.WebsocketUpgrade, - Timeout: convertHTTPTimeout(in.HttpReqTimeout), - Retries: convertRetry(in.HttpReqRetries), - Fault: convertHTTPFault(in.HttpFault), - Mirror: convertMirror(in.Mirror), - CorsPolicy: convertCORSPolicy(in.CorsPolicy), - AppendHeaders: in.AppendHeaders, - } -} - -func convertMatch(in *v1alpha1.MatchCondition) []*v1alpha3.HTTPMatchRequest { - if in == nil { - return nil - } - - out := &v1alpha3.HTTPMatchRequest{ - Headers: make(map[string]*v1alpha3.StringMatch), - } - - if in.Request != nil { - for name, stringMatch := range in.Request.Headers { - switch name { - case model.HeaderMethod: - out.Method = convertStringMatch(stringMatch) - case model.HeaderAuthority: - out.Authority = convertStringMatch(stringMatch) - case model.HeaderScheme: - out.Scheme = convertStringMatch(stringMatch) - case model.HeaderURI: - out.Uri = convertStringMatch(stringMatch) - default: - out.Headers[name] = convertStringMatch(stringMatch) - } - } - } - - if in.Tcp != nil { - log.Warn("TCP matching not supported") - } - if in.Udp != nil { - log.Warn("UDP matching not supported") - } - if in.Source != nil { - // TODO: out.SourceLabels - log.Warn("Source matching not supported") - } - - return []*v1alpha3.HTTPMatchRequest{out} -} - -func convertStringMatch(in *v1alpha1.StringMatch) *v1alpha3.StringMatch { - out := &v1alpha3.StringMatch{} - switch m := in.MatchType.(type) { - case *v1alpha1.StringMatch_Exact: - out.MatchType = &v1alpha3.StringMatch_Exact{Exact: m.Exact} - case *v1alpha1.StringMatch_Prefix: - out.MatchType = &v1alpha3.StringMatch_Prefix{Prefix: m.Prefix} - case *v1alpha1.StringMatch_Regex: - out.MatchType = &v1alpha3.StringMatch_Regex{Regex: m.Regex} - default: - log.Warn("Unsupported string match type") - return nil - } - return out -} - -func convertRoutes(in *v1alpha1.RouteRule) []*v1alpha3.DestinationWeight { - host := convertIstioService(in.Destination) - - var out []*v1alpha3.DestinationWeight - if in.Redirect == nil && len(in.Route) == 0 { - out = append(out, &v1alpha3.DestinationWeight{ - Destination: &v1alpha3.Destination{ - Host: host, - Subset: "", - Port: nil, - }, - Weight: 100, - }) - } - - for _, route := range in.Route { - name := host - if route.Destination != nil { - name = convertIstioService(route.Destination) - } - - out = append(out, &v1alpha3.DestinationWeight{ - Destination: &v1alpha3.Destination{ - Host: name, - Subset: labelsToSubsetName(route.Labels), - Port: nil, - }, - Weight: route.Weight, - }) - } - - return out -} - -func convertRedirect(in *v1alpha1.HTTPRedirect) *v1alpha3.HTTPRedirect { - if in == nil { - return nil - } - - out := v1alpha3.HTTPRedirect{ - Uri: in.Uri, - Authority: in.Authority, - } - - return &out -} - -func convertRewrite(in *v1alpha1.HTTPRewrite) *v1alpha3.HTTPRewrite { - if in == nil { - return nil - } - - out := v1alpha3.HTTPRewrite{ - Uri: in.Uri, - Authority: in.Authority, - } - return &out -} - -func convertHTTPTimeout(in *v1alpha1.HTTPTimeout) *types.Duration { - if in == nil { - return nil - } - - if st := in.GetSimpleTimeout(); st != nil { - if st.OverrideHeaderName != "" { - log.Warn("Timeout override header name not supported, ignored") - } - - return convertGogoDuration(st.Timeout) - } - - if ct := in.GetCustom(); ct != nil { - log.Warn("Custom timeout policy not supported") - } - - return nil -} - -func convertRetry(in *v1alpha1.HTTPRetry) *v1alpha3.HTTPRetry { - if in == nil { - return nil - } - - switch v := in.RetryPolicy.(type) { - case *v1alpha1.HTTPRetry_SimpleRetry: - if v.SimpleRetry.OverrideHeaderName != "" { - log.Warn("Simple retry override header name not supported") - } - - return &v1alpha3.HTTPRetry{ - Attempts: v.SimpleRetry.Attempts, - PerTryTimeout: convertGogoDuration(v.SimpleRetry.PerTryTimeout), - } - case *v1alpha1.HTTPRetry_Custom: - log.Warn("Custom retry not supported") - } - return nil -} - -func convertHTTPFault(in *v1alpha1.HTTPFaultInjection) *v1alpha3.HTTPFaultInjection { - if in == nil { - return nil - } - - return &v1alpha3.HTTPFaultInjection{ - Abort: convertFaultAbort(in.Abort), - Delay: convertFaultDelay(in.Delay), - } -} - -func convertFaultAbort(in *v1alpha1.HTTPFaultInjection_Abort) *v1alpha3.HTTPFaultInjection_Abort { - if in == nil { - return nil - } - - out := &v1alpha3.HTTPFaultInjection_Abort{ - Percent: convertPercent(in.Percent), - } - - if in.OverrideHeaderName != "" { - log.Warn("Abort override header name not supported") - } - - switch v := in.ErrorType.(type) { - case *v1alpha1.HTTPFaultInjection_Abort_HttpStatus: - out.ErrorType = &v1alpha3.HTTPFaultInjection_Abort_HttpStatus{HttpStatus: v.HttpStatus} - case *v1alpha1.HTTPFaultInjection_Abort_GrpcStatus: - out.ErrorType = &v1alpha3.HTTPFaultInjection_Abort_GrpcStatus{GrpcStatus: v.GrpcStatus} - case *v1alpha1.HTTPFaultInjection_Abort_Http2Error: - out.ErrorType = &v1alpha3.HTTPFaultInjection_Abort_Http2Error{Http2Error: v.Http2Error} - } - - return out -} - -func convertFaultDelay(in *v1alpha1.HTTPFaultInjection_Delay) *v1alpha3.HTTPFaultInjection_Delay { - if in == nil { - return nil - } - - out := &v1alpha3.HTTPFaultInjection_Delay{ - Percent: convertPercent(in.Percent), - } - - if in.OverrideHeaderName != "" { - log.Warn("Delay override header name not supported") - } - - switch v := in.HttpDelayType.(type) { - case *v1alpha1.HTTPFaultInjection_Delay_ExponentialDelay: - log.Warn("Exponential delay is not supported") - return nil - case *v1alpha1.HTTPFaultInjection_Delay_FixedDelay: - out.HttpDelayType = &v1alpha3.HTTPFaultInjection_Delay_FixedDelay{ - FixedDelay: convertGogoDuration(v.FixedDelay)} - } - - return out -} - -func convertPercent(in float32) int32 { - out := int32(in) - if in != float32(out) { - log.Warn("Percent truncated") - } - return out -} - -func convertMirror(in *v1alpha1.IstioService) *v1alpha3.Destination { - if in == nil { - return nil - } - - return &v1alpha3.Destination{ - Host: convertIstioService(in), - Subset: labelsToSubsetName(in.Labels), - } -} - -func convertCORSPolicy(in *v1alpha1.CorsPolicy) *v1alpha3.CorsPolicy { - if in == nil { - return nil - } - - return &v1alpha3.CorsPolicy{ - AllowOrigin: in.AllowOrigin, - AllowMethods: in.AllowMethods, - AllowHeaders: in.AllowHeaders, - ExposeHeaders: in.ExposeHeaders, - MaxAge: convertGogoDuration(in.MaxAge), - AllowCredentials: &types.BoolValue{Value: in.AllowCredentials.Value}, - } -} - -// TODO: domain, namespace etc? -// convert an Istio service to a v1alpha3 host -func convertIstioService(service *v1alpha1.IstioService) string { - if service.Service != "" { // Favor FQDN - return service.Service - } - return service.Name // otherwise shortname -} - -// create an unique DNS1123 friendly string -func labelsToSubsetName(labels model.Labels) string { - return strings.NewReplacer("=", "-", - ".", "-").Replace(labels.String()) -} - -func convertGogoDuration(in *duration.Duration) *types.Duration { - return &types.Duration{ - Seconds: in.Seconds, - Nanos: in.Nanos, - } -} - -// RouteRuleRouteLabels converts v1alpha1 route rule route labels to v1alpha3 destination rules -func RouteRuleRouteLabels(generateds []model.Config, configs []model.Config) []model.Config { - ruleConfigs := make([]model.Config, 0) - for _, config := range configs { - if config.Type == model.RouteRule.Type { - ruleConfigs = append(ruleConfigs, config) - } - } - - model.SortRouteRules(ruleConfigs) - - routeRules := make([]*v1alpha1.RouteRule, 0) - for _, ruleConfig := range ruleConfigs { - routeRules = append(routeRules, ruleConfig.Spec.(*v1alpha1.RouteRule)) - } - - destinationRules := make(map[string]*v1alpha3.DestinationRule) // host -> destination rule - - // Populate with DestinationRules that have already been generated - for _, generated := range generateds { - if generated.Type == model.DestinationRule.Type { - destinationRule := generated.Spec.(*v1alpha3.DestinationRule) - destinationRules[destinationRule.Host] = destinationRule - } - } - - // Track rules for hosts we don't already have a DestinationRule for - newDestinationRules := make(map[string]*v1alpha3.DestinationRule) // host -> destination rule - - for _, routeRule := range routeRules { - host := convertIstioService(routeRule.Destination) - rule, ok := destinationRules[host] - if !ok { - // There is no existing DestinationRule to merge with; create a new one - rule = &v1alpha3.DestinationRule{ - Host: host, - Subsets: make([]*v1alpha3.Subset, 0), - } - - destinationRules[host] = rule - newDestinationRules[host] = rule - } - - // Merge required Subsets with existing Subsets - for _, subset := range convertRouteRuleLabels(routeRule) { - found := false - for _, candidate := range rule.Subsets { - if candidate.Name == subset.Name { - // A subset by this name already exists. As the names are generated we expect labels to match - found = true - break - } - } - - if !found { - // We did not find an existing subset with the expected name; use the Subset converted from the Route - rule.Subsets = append(rule.Subsets, subset) - } - } - } - - out := make([]model.Config, 0) - for host, newDestinationRule := range newDestinationRules { - if len(newDestinationRule.Subsets) > 0 { - out = append(out, model.Config{ - ConfigMeta: model.ConfigMeta{ - Type: model.DestinationRule.Type, - Name: host, - Namespace: configs[0].Namespace, - Domain: configs[0].Domain, - }, - Spec: newDestinationRule, - }) - } - } - - return out -} - -func convertRouteRuleLabels(in *v1alpha1.RouteRule) []*v1alpha3.Subset { - - subsets := make([]*v1alpha3.Subset, 0) - - for _, route := range in.Route { - subsets = append(subsets, &v1alpha3.Subset{ - Name: labelsToSubsetName(route.Labels), - Labels: route.Labels, - }) - } - - return subsets -}