Skip to content

Commit

Permalink
version fixes (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuval-k authored and jenshu committed Jan 18, 2024
1 parent a87c855 commit f6dc5b8
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
go-version: "1.21"
- name: Build
run: go build -v ./projects/gateway2/...
run: go build -v ./projects/gateway2/... ./projects/gloo/cli/cmd
- name: Install utils for env tests
run: make -C ./projects/gateway2/ install-go-tools
- name: Test with the Go CLI
Expand Down
20 changes: 15 additions & 5 deletions projects/gateway2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ ifneq (,$(TAGGED_VERSION))
VERSION := $(shell echo $(TAGGED_VERSION) | cut -c 2-)
endif

LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)"

build:
CGO_ENABLED=0 GOOS=linux go build -o gloo-gateway
CGO_ENABLED=0 GOOS=linux go build -ldflags=$(LDFLAGS) -o gloo-gateway

build-glooctl:
CGO_ENABLED=0 GOOS=linux go build -ldflags=$(LDFLAGS) -o glooctl ../../projects/gloo/cli/cmd

docker: build
docker build -t ghcr.io/solo-io/gloo-gateway/glood:$(VERSION) .
docker pull quay.io/solo-io/envoy-gloo:1.26.4-patch4
docker tag quay.io/solo-io/envoy-gloo:1.26.4-patch4 ghcr.io/solo-io/gloo-gateway/gloo-proxy:$(VERSION)

push: docker
docker push ghcr.io/solo-io/gloo-gateway/glood:$(VERSION)
docker pull quay.io/solo-io/envoy-gloo:1.26.4-patch4
docker tag quay.io/solo-io/envoy-gloo:1.26.4-patch4 ghcr.io/solo-io/gloo-gateway/gloo-proxy:$(VERSION)
docker push ghcr.io/solo-io/gloo-gateway/gloo-proxy:$(VERSION)

.PHONY: helm
Expand All @@ -27,6 +32,7 @@ crds/gateway-crds.yaml:
kind:
./kind.sh
kind load docker-image ghcr.io/solo-io/gloo-gateway/glood:$(VERSION)
kind load docker-image ghcr.io/solo-io/gloo-gateway/gloo-proxy:$(VERSION)
helm upgrade -i default ./helm/gloo-gateway/ --set controlPlane.image.tag=$(VERSION) --set gateway.enabled=false --set develop=true
kubectl delete rs --all

Expand All @@ -37,12 +43,16 @@ tests/conformance/conformance_test.go:

CONFORMANCE_ARGS:=-gateway-class=gloo-gateway -supported-features=Gateway,HTTPRoute

.PHONY: test
test:
go test -ldflags=$(LDFLAGS) ./...

.PHONY: conformance
conformance: tests/conformance/conformance_test.go
go test -tags conformance -test.v ./tests/conformance/... -args $(CONFORMANCE_ARGS)
go test -ldflags=$(LDFLAGS) -tags conformance -test.v ./tests/conformance/... -args $(CONFORMANCE_ARGS)

conformance-%: tests/conformance/conformance_test.go
go test -tags conformance -test.v ./tests/conformance/... -args $(CONFORMANCE_ARGS) \
go test -ldflags=$(LDFLAGS) -tags conformance -test.v ./tests/conformance/... -args $(CONFORMANCE_ARGS) \
-run-test=$*

# internal target used by controller_suite_test.go
Expand Down
7 changes: 7 additions & 0 deletions projects/gateway2/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/fs"
"path/filepath"

"github.com/solo-io/gloo/pkg/version"
"github.com/solo-io/gloo/projects/gateway2/helm"
"github.com/solo-io/gloo/projects/gateway2/ports"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -49,6 +50,12 @@ func NewDeployer(scheme *runtime.Scheme, dev bool, controllerName, host string,
// don't retrun an error is requeueing won't help here
return nil, err
}
// simulate what `helm package` in the Makefile does
if version.Version != version.UndefinedVersion {
chart.Metadata.AppVersion = version.Version
chart.Metadata.Version = version.Version
}

return &Deployer{
dev: dev,
chart: chart,
Expand Down
91 changes: 91 additions & 0 deletions projects/gateway2/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -15,6 +16,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
api "sigs.k8s.io/gateway-api/apis/v1"

"github.com/solo-io/gloo/pkg/version"
"github.com/solo-io/gloo/projects/gateway2/controller/scheme"
"github.com/solo-io/gloo/projects/gateway2/deployer"
)
Expand Down Expand Up @@ -154,6 +156,95 @@ var _ = Describe("Deployer", func() {
Expect(port.TargetPort.IntVal).To(Equal(int32(8080)))
})

It("should work with multiple duplicate ports", func() {
version.Version = "testversion"
gw := &api.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
UID: "1235",
},
TypeMeta: metav1.TypeMeta{
Kind: "Gateway",
APIVersion: "gateway.solo.io/v1beta1",
},
Spec: api.GatewaySpec{
Listeners: []api.Listener{
{
Name: "listener-1",
Port: 80,
},
{
Name: "listener-2",
Port: 80,
},
},
},
}
objs, err := d.GetObjsToDeploy(context.Background(), gw)

Expect(err).NotTo(HaveOccurred())
Expect(objs).NotTo(BeEmpty())

svc := func() *corev1.Service {
for _, obj := range objs {
if svc, ok := obj.(*corev1.Service); ok {
return svc
}
}
return nil
}()
Expect(svc).NotTo(BeNil())

Expect(svc.Spec.Ports).To(HaveLen(1))
port := svc.Spec.Ports[0]
Expect(port.Port).To(Equal(int32(80)))
Expect(port.TargetPort.IntVal).To(Equal(int32(8080)))
})

It("should propagate version.Version to get deployment", func() {
version.Version = "testversion"
d, err := deployer.NewDeployer(scheme.NewScheme(), false, "foo", "xds", 8080)
Expect(err).NotTo(HaveOccurred())
gw := &api.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
UID: "1235",
},
TypeMeta: metav1.TypeMeta{
Kind: "Gateway",
APIVersion: "gateway.solo.io/v1beta1",
},
Spec: api.GatewaySpec{
Listeners: []api.Listener{
{
Name: "listener-1",
Port: 80,
},
},
},
}
objs, err := d.GetObjsToDeploy(context.Background(), gw)

Expect(err).NotTo(HaveOccurred())
Expect(objs).NotTo(BeEmpty())

dep := func() *appsv1.Deployment {
for _, obj := range objs {
if dep, ok := obj.(*appsv1.Deployment); ok {
return dep
}
}
return nil
}()
Expect(dep).NotTo(BeNil())
Expect(dep.Spec.Template.Spec.Containers).NotTo(BeEmpty())
for _, c := range dep.Spec.Template.Spec.Containers {
Expect(c.Image).To(HaveSuffix(":testversion"))
}
})

It("should get objects with owner refs", func() {
gw := &api.Gateway{
ObjectMeta: metav1.ObjectMeta{
Expand Down
4 changes: 2 additions & 2 deletions projects/gateway2/helm/gloo-gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ gateway:
protocol: TCP
name: http
image:
repository: quay.io/solo-io/envoy-gloo
repository: ghcr.io/solo-io/gloo-gateway/gloo-proxy
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "1.26.4-patch4"
tag: ""
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
Expand Down
2 changes: 1 addition & 1 deletion projects/gloo/cli/pkg/cmd/check/internal/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func CheckHTTPRoutes(ctx context.Context, printer printers.P, opts *options.Opti

for parent_idx := range httpRouteList.Items[route_idx].Spec.ParentRefs {
parent_ref := httpRouteList.Items[route_idx].Spec.ParentRefs[parent_idx]
child_idx := slices.IndexFunc[gwv1.RouteParentStatus](
child_idx := slices.IndexFunc(
httpRouteList.Items[route_idx].Status.Parents,
func(status_parent gwv1.RouteParentStatus) bool {
// Return the idx if we find the parent_ref in the status
Expand Down

0 comments on commit f6dc5b8

Please sign in to comment.