Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Update with initial test of HTTPProxy conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Young <ynick@vmware.com>
  • Loading branch information
Nick Young authored and youngnick committed Nov 29, 2019
1 parent e782e90 commit 9c63c67
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
57 changes: 46 additions & 11 deletions cmd/ir2proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package main

import (
"bytes"
"io/ioutil"
"os"

"github.com/davecgh/go-spew/spew"
irv1beta1 "github.com/projectcontour/contour/apis/contour/v1beta1"
contourscheme "github.com/projectcontour/contour/apis/generated/clientset/versioned/scheme"
hpv1 "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/sirupsen/logrus"
kingpin "gopkg.in/alecthomas/kingpin.v2"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
)

Expand Down Expand Up @@ -35,18 +39,31 @@ func main() {
}

contourscheme.AddToScheme(scheme.Scheme)
// This doesn't currently work with multiple objects in the one file.
decode := scheme.Codecs.UniversalDeserializer().Decode

ir, groupVersionKind, err := decode(data, nil, nil)
if err != nil {
log.Fatal(err)
}
switch t := ir.(type) {
case *irv1beta1.IngressRoute:
log.Infof("IngressRoute %s, namespace %s", t.ObjectMeta.Name, t.ObjectMeta.Namespace)
default:
log.Infof("This utility only works with IngressRoute, a %s was supplied.", groupVersionKind)
for _, yamldoc := range bytes.Split(data, []byte("---")) {
if len(yamldoc) == 0 {
continue
}

decode := scheme.Codecs.UniversalDeserializer().Decode

ir, groupVersionKind, err := decode(yamldoc, nil, nil)
if err != nil {
log.Infof("Skipped yaml doc, %s", err)
continue
}
switch t := ir.(type) {
case *irv1beta1.IngressRoute:
log.Infof("IngressRoute %s, namespace %s, labels %s", t.ObjectMeta.Name, t.ObjectMeta.Namespace, t.ObjectMeta.Labels)
hp, err := translateIngressRouteToHTTPProxy(t)
if err != nil {
log.Fatal(err)
}
log.Error(spew.Sdump(hp))
default:
log.Errorf("This utility only works with IngressRoute, a %s was supplied.", groupVersionKind)
}

}

}
Expand All @@ -59,3 +76,21 @@ func verifyYAMLFile(filename string) bool {
return !info.IsDir()

}

func translateIngressRouteToHTTPProxy(ir *irv1beta1.IngressRoute) (hp *hpv1.HTTPProxy, err error) {

hp = &hpv1.HTTPProxy{
ObjectMeta: v1.ObjectMeta{
Name: ir.ObjectMeta.Name,
Namespace: ir.ObjectMeta.Namespace,
Labels: ir.ObjectMeta.DeepCopy().GetLabels(),
Annotations: ir.ObjectMeta.DeepCopy().GetAnnotations(),
},
}

if ir.Spec.VirtualHost != nil {
hp.Spec.VirtualHost = ir.Spec.VirtualHost
}

return hp, err
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ go 1.13

require (
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/davecgh/go-spew v1.1.1
github.com/projectcontour/contour v1.0.0
github.com/sirupsen/logrus v1.4.2
gopkg.in/alecthomas/kingpin.v2 v2.2.6
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
k8s.io/client-go v0.0.0-20190918200256-06eb1244587a
)

0 comments on commit 9c63c67

Please sign in to comment.