Skip to content

Commit 58dbe20

Browse files
authored
Merge pull request #29 from dweomer/munge-semver-metadata-in-tags
munge plan.status.latestVersion
2 parents 1510bb8 + 81b1809 commit 58dbe20

File tree

13 files changed

+230
-156
lines changed

13 files changed

+230
-156
lines changed

.drone.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ steps:
1111
image: rancher/dapper:v0.4.2
1212
commands:
1313
- dapper ci
14+
- dapper e2e-sonobuoy
1415
- dapper e2e-verify
1516
volumes:
1617
- name: docker

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TARGETS := $(shell ls scripts)
1010
$(TARGETS): .dapper
1111
./.dapper $@
1212

13-
e2e: e2e-verify
13+
e2e: | e2e-sonobuoy e2e-verify
1414

1515
clean:
1616
rm -rvf ./bin ./dist

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ make e2e
131131

132132
This will, via Dapper, stand up a local cluster (using docker-compose) and then run the Sonobuoy plugin against/within it.
133133
The Sonobuoy results are parsed and a `Status: passed` results in a clean exit, whereas `Status: failed` exits non-zero.
134-
See [scripts/e2e-results](scripts/e2e-results) called by [scripts/e2e-verify](scripts/e2e-verify).
135134

136135
Alternatively, if you have a working cluster and Sonobuoy installation, provided you've pushed the images (consider building with
137136
something like `make REPO=dweomer TAG=dev`), then you can run the e2e tests thusly:

e2e/cluster/local/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
hostname: local-leader
2020
privileged: true
2121
ports:
22-
- "172.17.0.1:6443:6443" # k3s
22+
- "6443:6443" # k3s
2323
volumes:
2424
- source: kubeconfig
2525
target: /etc/rancher/k3s

e2e/framework/channel.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package framework
2+
3+
import (
4+
"net"
5+
"net/http"
6+
"net/http/httptest"
7+
"os"
8+
)
9+
10+
func ChannelServer(location string) *httptest.Server {
11+
hostname, err := os.Hostname()
12+
if err != nil {
13+
Failf("cannot read hostname: %v", err)
14+
}
15+
server := &httptest.Server{
16+
Config: &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17+
w.Header().Set("Location", location)
18+
w.WriteHeader(http.StatusFound)
19+
})},
20+
}
21+
server.Listener, err = net.Listen("tcp", net.JoinHostPort(hostname, "0"))
22+
if err != nil {
23+
Failf("cannot create tcp listener: %v", err)
24+
}
25+
server.Start()
26+
return server
27+
}

e2e/framework/framework.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ package framework
22

33
import (
44
"fmt"
5-
"net"
6-
"net/http"
7-
"net/http/httptest"
8-
"os"
95
"strings"
106
"time"
117

@@ -46,8 +42,6 @@ type Client struct {
4642

4743
controllerDeployment *appsv1.Deployment
4844
controllerServiceAccount *corev1.ServiceAccount
49-
50-
channelServer *httptest.Server
5145
}
5246

5347
func New(name string, opt ...Option) *Client {
@@ -90,10 +84,6 @@ func (c *Client) NewPlan(name, image string, command []string, args ...string) *
9084
return plan
9185
}
9286

93-
func (c *Client) ChannelServerURL() string {
94-
return c.channelServer.URL
95-
}
96-
9787
func (c *Client) CreatePlan(plan *upgradeapiv1.Plan) (*upgradeapiv1.Plan, error) {
9888
return c.UpgradeClientSet.UpgradeV1().Plans(c.Namespace.Name).Create(plan)
9989
}
@@ -140,36 +130,12 @@ func (c *Client) BeforeEach() {
140130
c.beforeFramework()
141131
c.Framework.BeforeEach()
142132
c.setupController()
143-
c.setupChannelServer()
144133
}
145134

146135
func (c *Client) AfterEach() {
147-
c.teardownChannelServer()
148136
c.Framework.AfterEach()
149137
}
150138

151-
func (c *Client) setupChannelServer() {
152-
hostname, err := os.Hostname()
153-
if err != nil {
154-
Failf("cannot read hostname: %v", err)
155-
}
156-
c.channelServer = &httptest.Server{
157-
Config: &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
158-
w.Header().Set("Location", "/local/channel/test")
159-
w.WriteHeader(http.StatusFound)
160-
})},
161-
}
162-
c.channelServer.Listener, err = net.Listen("tcp", net.JoinHostPort(hostname, "0"))
163-
if err != nil {
164-
Failf("cannot create tcp listener: %v", err)
165-
}
166-
c.channelServer.Start()
167-
}
168-
169-
func (c *Client) teardownChannelServer() {
170-
c.channelServer.Close()
171-
}
172-
173139
func (c *Client) setupController() {
174140
var err error
175141
c.controllerServiceAccount, err = c.ClientSet.CoreV1().ServiceAccounts(c.Namespace.Name).Create(&corev1.ServiceAccount{

e2e/suite/plan_resolve_test.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package suite_test
2+
3+
import (
4+
"net/http/httptest"
5+
"path"
6+
"time"
7+
8+
"github.com/rancher/system-upgrade-controller/e2e/framework"
9+
upgradeapiv1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
10+
)
11+
12+
var _ = Describe("Upgrade", func() {
13+
e2e := framework.New("resolve")
14+
15+
When("plan missing channel and version", func() {
16+
var (
17+
err error
18+
plan = e2e.NewPlan("missing-", "", nil)
19+
)
20+
BeforeEach(func() {
21+
plan, err = e2e.CreatePlan(plan)
22+
Expect(err).ToNot(HaveOccurred())
23+
24+
plan, err = e2e.PollPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 2*time.Second, 30*time.Second)
25+
Expect(err).ToNot(HaveOccurred())
26+
})
27+
It("should not resolve", func() {
28+
Expect(upgradeapiv1.PlanLatestResolved.MatchesError(plan, "Error", upgradeapiv1.ErrPlanUnresolvable)).To(BeTrue())
29+
Expect(plan.Status.LatestVersion).To(BeEmpty())
30+
Expect(plan.Status.LatestHash).To(BeEmpty())
31+
})
32+
})
33+
34+
When("plan has version", func() {
35+
var (
36+
err error
37+
plan = e2e.NewPlan("version-", "", nil)
38+
)
39+
BeforeEach(func() {
40+
plan.Spec.Version = "test"
41+
42+
plan, err = e2e.CreatePlan(plan)
43+
Expect(err).ToNot(HaveOccurred())
44+
45+
plan, err = e2e.PollPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 2*time.Second, 30*time.Second)
46+
Expect(err).ToNot(HaveOccurred())
47+
})
48+
It("should resolve", func() {
49+
Expect(upgradeapiv1.PlanLatestResolved.IsTrue(plan)).To(BeTrue())
50+
Expect(upgradeapiv1.PlanLatestResolved.GetReason(plan)).To(Equal("Version"))
51+
Expect(plan.Status.LatestVersion).To(Equal(plan.Spec.Version))
52+
Expect(plan.Status.LatestHash).ToNot(BeEmpty())
53+
})
54+
})
55+
56+
When("plan has version with semver+metadata", func() {
57+
var (
58+
err error
59+
plan = e2e.NewPlan("version-semver-metadata-", "", nil)
60+
semver = "v1.2.3+test"
61+
)
62+
BeforeEach(func() {
63+
plan.Spec.Version = semver
64+
65+
plan, err = e2e.CreatePlan(plan)
66+
Expect(err).ToNot(HaveOccurred())
67+
68+
plan, err = e2e.PollPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 2*time.Second, 30*time.Second)
69+
Expect(err).ToNot(HaveOccurred())
70+
})
71+
It("should resolve", func() {
72+
Expect(upgradeapiv1.PlanLatestResolved.IsTrue(plan)).To(BeTrue())
73+
Expect(upgradeapiv1.PlanLatestResolved.GetReason(plan)).To(Equal("Version"))
74+
Expect(plan.Status.LatestHash).ToNot(BeEmpty())
75+
})
76+
It("should munge the semver", func() {
77+
Expect(plan.Status.LatestVersion).ToNot(ContainSubstring(`+`))
78+
})
79+
})
80+
81+
When("plan has channel", func() {
82+
var (
83+
err error
84+
plan = e2e.NewPlan("channel-", "", nil)
85+
channelSrv *httptest.Server
86+
channelTag = "test"
87+
)
88+
BeforeEach(func() {
89+
channelSrv = framework.ChannelServer(path.Join("/local", channelTag))
90+
plan.Spec.Channel = channelSrv.URL
91+
Expect(plan.Spec.Channel).ToNot(BeEmpty())
92+
93+
plan, err = e2e.CreatePlan(plan)
94+
Expect(err).ToNot(HaveOccurred())
95+
96+
plan, err = e2e.PollPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 2*time.Second, 30*time.Second)
97+
Expect(err).ToNot(HaveOccurred())
98+
})
99+
AfterEach(func() {
100+
if channelSrv != nil {
101+
channelSrv.Close()
102+
}
103+
})
104+
It("should resolve", func() {
105+
Expect(upgradeapiv1.PlanLatestResolved.IsTrue(plan)).To(BeTrue())
106+
Expect(upgradeapiv1.PlanLatestResolved.GetReason(plan)).To(Equal("Channel"))
107+
Expect(plan.Status.LatestVersion).To(Equal(channelTag))
108+
Expect(plan.Status.LatestHash).ToNot(BeEmpty())
109+
})
110+
})
111+
112+
When("plan has channel with semver+metadata", func() {
113+
var (
114+
err error
115+
plan = e2e.NewPlan("channel-semver-metadata-", "", nil)
116+
channelSrv *httptest.Server
117+
channelTag = "v1.2.3+test"
118+
)
119+
BeforeEach(func() {
120+
channelSrv = framework.ChannelServer(path.Join("/local/test", channelTag))
121+
plan.Spec.Channel = channelSrv.URL
122+
Expect(plan.Spec.Channel).ToNot(BeEmpty())
123+
124+
plan, err = e2e.CreatePlan(plan)
125+
Expect(err).ToNot(HaveOccurred())
126+
127+
plan, err = e2e.PollPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 2*time.Second, 30*time.Second)
128+
Expect(err).ToNot(HaveOccurred())
129+
})
130+
AfterEach(func() {
131+
if channelSrv != nil {
132+
channelSrv.Close()
133+
}
134+
})
135+
It("should resolve", func() {
136+
Expect(upgradeapiv1.PlanLatestResolved.IsTrue(plan)).To(BeTrue())
137+
Expect(upgradeapiv1.PlanLatestResolved.GetReason(plan)).To(Equal("Channel"))
138+
Expect(plan.Status.LatestHash).ToNot(BeEmpty())
139+
})
140+
It("should munge the semver", func() {
141+
Expect(plan.Status.LatestVersion).ToNot(ContainSubstring(`+`))
142+
})
143+
})
144+
})

e2e/suite/upgrade_test.go

Lines changed: 0 additions & 67 deletions
This file was deleted.
File renamed without changes.

pkg/upgrade/plan/plan.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"sort"
11+
"strings"
1112
"time"
1213

1314
"github.com/rancher/norman/pkg/openapi"
@@ -164,7 +165,7 @@ func RegisterHandlers(ctx context.Context, controllerNamespace, controllerName s
164165
}
165166
if obj.Spec.Version != "" {
166167
resolved.SetError(obj, "Version", nil)
167-
obj.Status.LatestVersion = obj.Spec.Version
168+
obj.Status.LatestVersion = mungeVersionTag(obj.Spec.Version)
168169
return digestPlan(secretsCache, obj)
169170
}
170171
if resolved.IsTrue(obj) {
@@ -180,7 +181,7 @@ func RegisterHandlers(ctx context.Context, controllerNamespace, controllerName s
180181
return status, err
181182
}
182183
resolved.SetError(obj, "Channel", nil)
183-
obj.Status.LatestVersion = latest
184+
obj.Status.LatestVersion = mungeVersionTag(latest)
184185
return digestPlan(secretsCache, obj)
185186
},
186187
)
@@ -312,3 +313,7 @@ func selectConcurrentNodeNames(nodeCache corectlv1.NodeCache, plan *upgradeapiv1
312313
sort.Strings(selected)
313314
return selected, nil
314315
}
316+
317+
func mungeVersionTag(version string) string {
318+
return strings.ReplaceAll(version, `+`, `-`)
319+
}

scripts/e2e-results

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)