Skip to content

Commit

Permalink
Remove dep on istio switch to unstructured
Browse files Browse the repository at this point in the history
Signed-off-by: zachaller <[email protected]>
  • Loading branch information
zachaller committed May 12, 2022
1 parent 8d1a57e commit a5a5802
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 44 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ require (
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
istio.io/client-go v1.13.3
k8s.io/api v0.23.3
k8s.io/apiextensions-apiserver v0.23.1
k8s.io/apimachinery v0.23.3
Expand Down Expand Up @@ -163,8 +162,6 @@ require (
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
istio.io/api v0.0.0-20220413180505-1574de06b7bd // indirect
istio.io/gogo-genproto v0.0.0-20211208193508-5ab4acc9eb1e // indirect
k8s.io/cluster-bootstrap v0.0.0 // indirect
k8s.io/component-helpers v0.23.1 // indirect
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1480,12 +1480,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
istio.io/api v0.0.0-20220413180505-1574de06b7bd h1:2i0e183JpTuZkZzqgXlv3mosCBxv7Bt9uUB4cNe7iSM=
istio.io/api v0.0.0-20220413180505-1574de06b7bd/go.mod h1:8ZZgyVgYrHhsFQarEgTfPnMGpdgTDZbxSjYhdwTUuAQ=
istio.io/client-go v1.13.3 h1:xbEgTX4NRlvVRI/JsCmMI0ATvCc9P85HkQ20SphEGZ4=
istio.io/client-go v1.13.3/go.mod h1:DeT/l4yO+bwyv0ZgavSTj7BfkA2cTckHD0jtluwtXhE=
istio.io/gogo-genproto v0.0.0-20211208193508-5ab4acc9eb1e h1:z2WI3y55w0K3c6hmarcp5EcOiP4vVpTBXA8nYstP+cE=
istio.io/gogo-genproto v0.0.0-20211208193508-5ab4acc9eb1e/go.mod h1:vJDAniIqryf/z///fgZqVPKJ7N2lBk7Gg8DCTB7oCfU=
k8s.io/api v0.23.1 h1:ncu/qfBfUoClqwkTGbeRqqOqBCRoUAflMuOaOD7J0c8=
k8s.io/api v0.23.1/go.mod h1:WfXnOnwSqNtG62Y1CdjoMxh7r7u9QXGCkA1u0na2jgo=
k8s.io/apiextensions-apiserver v0.23.1 h1:xxE0q1vLOVZiWORu1KwNRQFsGWtImueOrqSl13sS5EU=
Expand Down
46 changes: 11 additions & 35 deletions pkg/kubectl-argo-rollouts/cmd/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ import (
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
goyaml "gopkg.in/yaml.v2"
istioNetworkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
istioNetworkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
v1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
)

Expand Down Expand Up @@ -113,7 +109,7 @@ func (l *LintOptions) lintResource(path string) error {
}
fileRollouts = append(fileRollouts, ro)
}
err = buildAllReferencedResources(gvk, valueBytes, &refResource)
err = buildAllReferencedResources(un, &refResource)
if err != nil {
return err
}
Expand Down Expand Up @@ -144,7 +140,14 @@ func (l *LintOptions) lintResource(path string) error {
// buildAllReferencedResources This builds a ReferencedResources object that has all the external resources for every
// rollout resource in the manifest. We will need to later match each referenced resource to its own rollout resource
// before passing the rollout object and its managed reference on to validation.
func buildAllReferencedResources(gvk schema.GroupVersionKind, valueBytes []byte, refResource *validation.ReferencedResources) error {
func buildAllReferencedResources(un unstructured.Unstructured, refResource *validation.ReferencedResources) error {

valueBytes, err := un.MarshalJSON()
if err != nil {
return err
}

gvk := un.GroupVersionKind()
switch {
case gvk.Group == v1.GroupName && gvk.Kind == "Service":
var svc v1.Service
Expand All @@ -156,35 +159,8 @@ func buildAllReferencedResources(gvk schema.GroupVersionKind, valueBytes []byte,
Service: &svc,
})

case gvk.Group == istioNetworkingv1beta1.GroupName && gvk.Kind == "VirtualService":
var virtualServicev1beta1 istioNetworkingv1beta1.VirtualService
var virtualServicev1alpha3 istioNetworkingv1alpha3.VirtualService
if gvk.Version == "v1alpha3" {
err := unmarshal(valueBytes, &virtualServicev1alpha3)
if err != nil {
return err
}

vsvcUn, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&virtualServicev1alpha3)
if err != nil {
return err
}
refResource.VirtualServices = append(refResource.VirtualServices, unstructured.Unstructured{
Object: vsvcUn,
})
} else if gvk.Version == "v1beta1" {
err := unmarshal(valueBytes, &virtualServicev1beta1)
if err != nil {
return err
}
vsvcUn, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&virtualServicev1beta1)
if err != nil {
return err
}
refResource.VirtualServices = append(refResource.VirtualServices, unstructured.Unstructured{
Object: vsvcUn,
})
}
case gvk.Group == "networking.istio.io" && gvk.Kind == "VirtualService":
refResource.VirtualServices = append(refResource.VirtualServices, un)

case (gvk.Group == networkingv1.GroupName || gvk.Group == extensionsv1beta1.GroupName) && gvk.Kind == "Ingress":
var ing networkingv1.Ingress
Expand Down

0 comments on commit a5a5802

Please sign in to comment.