Skip to content

Commit e3c3ba6

Browse files
committed
chore: merge branch '3.6' into main;
2 parents a25308d + a9027ae commit e3c3ba6

File tree

184 files changed

+5777
-1455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+5777
-1455
lines changed

.github/api-client-allowed-list.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ gopkg.in/yaml.v2
4242
hash
4343
internal
4444
io
45+
iter
4546
log
47+
maps
4648
math
4749
mime
4850
net
@@ -60,6 +62,7 @@ syscall
6062
text
6163
time
6264
unicode
65+
unique
6366
unsafe
6467
vendor/golang.org/x
6568
iter

.github/golangci-lint.config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ linters-settings:
2020
- loopclosure
2121
- lostcancel
2222
- nilfunc
23-
- printf
23+
# TODO(4.0): re-enable me
24+
# - printf
2425
- shift
2526
- stdmethods
2627
- structtag

.github/workflows/context-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ jobs:
104104
terraform:
105105
needs: [changed-files]
106106
name: Terraform Smoke
107-
if: github.event.pull_request.draft == false && github.base_ref != 'main' && needs.changed-files.outputs.check-terraform == 'true'
107+
# TODO - always skip terraform tests until they are made reliable on 3.x branches.
108+
if: false && github.event.pull_request.draft == false && github.base_ref != 'main' && needs.changed-files.outputs.check-terraform == 'true'
108109
uses: ./.github/workflows/terraform-smoke.yml
109110

110111
migrate:

.github/workflows/gen.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ jobs:
2121
go-version-file: 'go.mod'
2222
cache: true
2323

24-
- name: "Delete all mocks"
25-
shell: bash
26-
# Ideally we'd delete all generated files, but we can't because some of
27-
# the Go code depends on generated files for go:generate to actually work.
28-
run: |
29-
for FILE in $(grep '// Code generated by MockGen. DO NOT EDIT.' -r . -l --include \*.go); do
30-
rm $FILE
31-
done
32-
3324
- name: "Regenerate code"
3425
shell: bash
3526
run: |
@@ -43,7 +34,7 @@ jobs:
4334
# 3. Unique every file, so we only go generate the file once.
4435
# 4. Using xargs perform go generate in parallel.
4536
#
46-
grep -ir "//go:generate" --include '*.go' . | awk -F : '{ print $1 }' | uniq | xargs -n 1 -P 8 -I% go generate -x $(realpath %)
37+
git ls-files | xargs grep "//go:generate" --include '*.go' | awk -F : '{ print $1 }' | uniq | xargs -n 1 -P 8 -I% sh -c "go generate -x $(realpath %) || (echo FAIL: % && exit 1)"
4738
4839
- name: "Check diff"
4940
shell: bash

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
libsqlite3-dev \
3939
sqlite3
4040
go install golang.org/x/vuln/cmd/govulncheck@latest
41-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
41+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
4242
sudo curl -sSfL https://github.com/mvdan/sh/releases/download/v3.7.0/shfmt_v3.7.0_linux_$(go env GOARCH) -o /usr/bin/shfmt
4343
sudo chmod +x /usr/bin/shfmt
4444

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ Read our [Code of conduct](https://ubuntu.com/community/code-of-conduct) and:
157157
### Make your mark
158158

159159
- Read our [documentation contributor guidelines](https://discourse.charmhub.io/t/documentation-guidelines-for-contributors/1245) and help improve a doc
160-
- Read our [codebase contributor guidelines](CONTRIBUTING.md) and help improve the codebase
160+
- Read our [codebase contributor guidelines](doc/CONTRIBUTING.md) and help improve the codebase

agent/addons/addons.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
package addons
55

66
import (
7+
"path"
78
"runtime"
89

910
"github.com/juju/clock"
1011
"github.com/juju/errors"
11-
"github.com/juju/names/v5"
1212
"github.com/juju/worker/v4"
1313
"github.com/juju/worker/v4/dependency"
1414
"github.com/prometheus/client_golang/prometheus"
@@ -26,17 +26,14 @@ type MetricSink interface {
2626
Unregister() bool
2727
}
2828

29-
// DefaultIntrospectionSocketName returns the socket name to use for the
30-
// abstract domain socket that the introspection worker serves requests
31-
// over.
32-
func DefaultIntrospectionSocketName(entityTag names.Tag) string {
33-
return "jujud-" + entityTag.String()
34-
}
29+
// IntrospectionSocketName is the name of the socket file inside
30+
// the agent's directory used for introspection calls.
31+
const IntrospectionSocketName = "introspection.socket"
3532

3633
// IntrospectionConfig defines the various components that the introspection
3734
// worker reports on or needs to start up.
3835
type IntrospectionConfig struct {
39-
AgentTag names.Tag
36+
AgentDir string
4037
Engine *dependency.Engine
4138
StatePoolReporter introspection.Reporter
4239
PubSubReporter introspection.Reporter
@@ -48,8 +45,7 @@ type IntrospectionConfig struct {
4845
CentralHub introspection.StructuredHub
4946
Logger logger.Logger
5047

51-
NewSocketName func(names.Tag) string
52-
WorkerFunc func(config introspection.Config) (worker.Worker, error)
48+
WorkerFunc func(config introspection.Config) (worker.Worker, error)
5349
}
5450

5551
// StartIntrospection creates the introspection worker. It cannot and should
@@ -64,7 +60,7 @@ func StartIntrospection(cfg IntrospectionConfig) error {
6460
return nil
6561
}
6662

67-
socketName := cfg.NewSocketName(cfg.AgentTag)
63+
socketName := path.Join(cfg.AgentDir, IntrospectionSocketName)
6864
w, err := cfg.WorkerFunc(introspection.Config{
6965
SocketName: socketName,
7066
DepEngine: cfg.Engine,

agent/addons/addons_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/juju/clock"
1111
"github.com/juju/errors"
1212
"github.com/juju/loggo/v2"
13-
"github.com/juju/names/v5"
1413
"github.com/juju/testing"
1514
jc "github.com/juju/testing/checkers"
1615
"github.com/juju/worker/v4"
@@ -56,8 +55,7 @@ func (s *introspectionSuite) TestStartError(c *gc.C) {
5655
}
5756

5857
cfg := addons.IntrospectionConfig{
59-
AgentTag: names.NewMachineTag("42"),
60-
NewSocketName: addons.DefaultIntrospectionSocketName,
58+
AgentDir: c.MkDir(),
6159
WorkerFunc: func(_ introspection.Config) (worker.Worker, error) {
6260
return nil, errors.New("boom")
6361
},
@@ -87,9 +85,8 @@ func (s *introspectionSuite) TestStartSuccess(c *gc.C) {
8785
c.Assert(err, jc.ErrorIsNil)
8886

8987
cfg := addons.IntrospectionConfig{
90-
AgentTag: names.NewMachineTag("42"),
91-
Engine: engine,
92-
NewSocketName: func(tag names.Tag) string { return "bananas" },
88+
AgentDir: c.MkDir(),
89+
Engine: engine,
9390
WorkerFunc: func(cfg introspection.Config) (worker.Worker, error) {
9491
fake.config = cfg
9592
return fake, nil
@@ -101,7 +98,7 @@ func (s *introspectionSuite) TestStartSuccess(c *gc.C) {
10198
c.Assert(err, jc.ErrorIsNil)
10299

103100
c.Check(fake.config.DepEngine, gc.Equals, engine)
104-
c.Check(fake.config.SocketName, gc.Equals, "bananas")
101+
c.Check(fake.config.SocketName, jc.HasSuffix, "introspection.socket")
105102

106103
// Stopping the engine causes the introspection worker to stop.
107104
engine.Kill()
@@ -113,11 +110,6 @@ func (s *introspectionSuite) TestStartSuccess(c *gc.C) {
113110
}
114111
}
115112

116-
func (s *introspectionSuite) TestDefaultIntrospectionSocketName(c *gc.C) {
117-
name := addons.DefaultIntrospectionSocketName(names.NewMachineTag("42"))
118-
c.Assert(name, gc.Equals, "jujud-machine-42")
119-
}
120-
121113
type dummyWorker struct {
122114
config introspection.Config
123115
done chan struct{}

agent/introspect/introspect.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http/httputil"
1111
"net/url"
1212
"os"
13+
"path"
1314
"path/filepath"
1415
"strings"
1516

@@ -19,6 +20,7 @@ import (
1920
"github.com/juju/names/v5"
2021
"github.com/kr/pretty"
2122

23+
"github.com/juju/juju/agent"
2224
"github.com/juju/juju/agent/addons"
2325
"github.com/juju/juju/agent/config"
2426
jujucmd "github.com/juju/juju/cmd"
@@ -35,16 +37,11 @@ type IntrospectCommand struct {
3537
verbose bool
3638
post bool
3739
form url.Values
38-
39-
// IntrospectionSocketName returns the socket name
40-
// for a given tag. If IntrospectionSocketName is nil,
41-
// agent.DefaultIntrospectionSocketName is used.
42-
IntrospectionSocketName func(names.Tag) string
4340
}
4441

4542
// New initializes IntrospectCommand.
46-
func New(sockNameGetter func(names.Tag) string) cmd.Command {
47-
return &IntrospectCommand{IntrospectionSocketName: sockNameGetter}
43+
func New() cmd.Command {
44+
return &IntrospectCommand{}
4845
}
4946

5047
const introspectCommandDoc = `
@@ -127,11 +124,7 @@ func (c *IntrospectCommand) Run(ctx *cmd.Context) error {
127124
return err
128125
}
129126

130-
getSocketName := c.IntrospectionSocketName
131-
if getSocketName == nil {
132-
getSocketName = addons.DefaultIntrospectionSocketName
133-
}
134-
socketName := "@" + getSocketName(tag)
127+
socketName := path.Join(agent.Dir(c.dataDir, tag), addons.IntrospectionSocketName)
135128
if c.listen != "" {
136129
listener, err := net.Listen("tcp", c.listen)
137130
if err != nil {

agent/introspect/introspect_test.go

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"github.com/juju/cmd/v4"
2222
"github.com/juju/cmd/v4/cmdtesting"
23-
"github.com/juju/names/v5"
2423
jc "github.com/juju/testing/checkers"
2524
gc "gopkg.in/check.v1"
2625

@@ -53,11 +52,7 @@ func (*IntrospectCommandSuite) assertInitError(c *gc.C, expect string, args ...s
5352
}
5453

5554
func (*IntrospectCommandSuite) run(c *gc.C, args ...string) (*cmd.Context, error) {
56-
return cmdtesting.RunCommand(c, &introspect.IntrospectCommand{
57-
IntrospectionSocketName: func(tag names.Tag) string {
58-
return filepath.Join(config.DataDir, "jujud-"+tag.String())
59-
},
60-
}, args...)
55+
return cmdtesting.RunCommand(c, &introspect.IntrospectCommand{}, args...)
6156
}
6257

6358
func (s *IntrospectCommandSuite) TestAutoDetectMachineAgent(c *gc.C) {
@@ -66,7 +61,7 @@ func (s *IntrospectCommandSuite) TestAutoDetectMachineAgent(c *gc.C) {
6661
c.Assert(err, jc.ErrorIsNil)
6762

6863
_, err = s.run(c, "query")
69-
c.Assert(err, gc.ErrorMatches, ".*jujud-machine-1024.*")
64+
c.Assert(err, gc.ErrorMatches, ".*machine-1024.*")
7065
}
7166

7267
func (s *IntrospectCommandSuite) TestAutoDetectMachineAgentFails(c *gc.C) {
@@ -80,11 +75,14 @@ func (s *IntrospectCommandSuite) TestAutoDetectMachineAgentFails(c *gc.C) {
8075

8176
func (s *IntrospectCommandSuite) TestAgentSpecified(c *gc.C) {
8277
_, err := s.run(c, "query", "--agent=unit-foo-0")
83-
c.Assert(err, gc.ErrorMatches, ".*jujud-unit-foo-0.*")
78+
c.Assert(err, gc.ErrorMatches, ".*unit-foo-0.*")
8479
}
8580

8681
func (s *IntrospectCommandSuite) TestQuery(c *gc.C) {
87-
listener, err := net.Listen("unix", "@"+filepath.Join(config.DataDir, "jujud-machine-0"))
82+
agentDir := filepath.Join(config.DataDir, "agents", "machine-0")
83+
err := os.MkdirAll(agentDir, 0755)
84+
c.Assert(err, jc.ErrorIsNil)
85+
listener, err := net.Listen("unix", filepath.Join(agentDir, "introspection.socket"))
8886
c.Assert(err, jc.ErrorIsNil)
8987
defer listener.Close()
9088

@@ -98,7 +96,10 @@ func (s *IntrospectCommandSuite) TestQuery(c *gc.C) {
9896
}
9997

10098
func (s *IntrospectCommandSuite) TestQueryFails(c *gc.C) {
101-
listener, err := net.Listen("unix", "@"+filepath.Join(config.DataDir, "jujud-machine-0"))
99+
agentDir := filepath.Join(config.DataDir, "agents", "machine-0")
100+
err := os.MkdirAll(agentDir, 0755)
101+
c.Assert(err, jc.ErrorIsNil)
102+
listener, err := net.Listen("unix", filepath.Join(agentDir, "introspection.socket"))
102103
c.Assert(err, jc.ErrorIsNil)
103104
defer listener.Close()
104105

@@ -118,7 +119,10 @@ func (s *IntrospectCommandSuite) TestQueryFails(c *gc.C) {
118119
}
119120

120121
func (s *IntrospectCommandSuite) TestGetToPostEndpoint(c *gc.C) {
121-
listener, err := net.Listen("unix", "@"+filepath.Join(config.DataDir, "jujud-machine-0"))
122+
agentDir := filepath.Join(config.DataDir, "agents", "machine-0")
123+
err := os.MkdirAll(agentDir, 0755)
124+
c.Assert(err, jc.ErrorIsNil)
125+
listener, err := net.Listen("unix", filepath.Join(agentDir, "introspection.socket"))
122126
c.Assert(err, jc.ErrorIsNil)
123127
defer listener.Close()
124128

@@ -133,7 +137,10 @@ func (s *IntrospectCommandSuite) TestGetToPostEndpoint(c *gc.C) {
133137
}
134138

135139
func (s *IntrospectCommandSuite) TestPost(c *gc.C) {
136-
listener, err := net.Listen("unix", "@"+filepath.Join(config.DataDir, "jujud-machine-0"))
140+
agentDir := filepath.Join(config.DataDir, "agents", "machine-0")
141+
err := os.MkdirAll(agentDir, 0755)
142+
c.Assert(err, jc.ErrorIsNil)
143+
listener, err := net.Listen("unix", filepath.Join(agentDir, "introspection.socket"))
137144
c.Assert(err, jc.ErrorIsNil)
138145
defer listener.Close()
139146

@@ -151,8 +158,11 @@ single="value"
151158
}
152159

153160
func (s *IntrospectCommandSuite) TestListen(c *gc.C) {
154-
socketName := filepath.Join(config.DataDir, "jujud-machine-0")
155-
listener, err := net.Listen("unix", "@"+socketName)
161+
agentDir := filepath.Join(config.DataDir, "agents", "machine-0")
162+
err := os.MkdirAll(agentDir, 0755)
163+
c.Assert(err, jc.ErrorIsNil)
164+
socketName := filepath.Join(agentDir, "introspection.socket")
165+
listener, err := net.Listen("unix", socketName)
156166
c.Assert(err, jc.ErrorIsNil)
157167
defer listener.Close()
158168

@@ -162,7 +172,7 @@ func (s *IntrospectCommandSuite) TestListen(c *gc.C) {
162172

163173
ctx, cancel := context.WithCancel(context.Background())
164174
defer cancel()
165-
cmd := exec.CommandContext(ctx, os.Args[0], "-run-listen="+socketName)
175+
cmd := exec.CommandContext(ctx, os.Args[0], "-run-listen="+config.DataDir)
166176
stderr, err := cmd.StderrPipe()
167177
c.Assert(err, jc.ErrorIsNil)
168178
defer stderr.Close()
@@ -172,7 +182,7 @@ func (s *IntrospectCommandSuite) TestListen(c *gc.C) {
172182
scanner := bufio.NewScanner(stderr)
173183
c.Assert(scanner.Scan(), jc.IsTrue)
174184
line := scanner.Text()
175-
c.Assert(line, gc.Matches, "Exposing @.* introspection socket on 127.0.0.1:.*")
185+
c.Assert(line, gc.Matches, "Exposing .* introspection socket on 127.0.0.1:.*")
176186

177187
fields := strings.Fields(line)
178188
addr := fields[len(fields)-1]
@@ -217,16 +227,12 @@ func newServer(l net.Listener) *http.Server {
217227
return srv
218228
}
219229

220-
var flagListen = flag.String("run-listen", "", "Name of the Unix socket to connect the introspect command to using --listen=:0")
230+
var flagListen = flag.String("run-listen", "", "DataDir of the Unix socket to connect the introspect command to using --listen=:0")
221231

222232
func TestRunListen(t *stdtesting.T) {
223233
if *flagListen != "" {
224-
introspectCommand := &introspect.IntrospectCommand{
225-
IntrospectionSocketName: func(names.Tag) string {
226-
return *flagListen
227-
},
228-
}
229-
args := append(flag.Args(), "--listen=127.0.0.1:0", "--agent=machine-0")
234+
introspectCommand := &introspect.IntrospectCommand{}
235+
args := append(flag.Args(), "--data-dir="+*flagListen, "--listen=127.0.0.1:0", "--agent=machine-0")
230236
if err := cmdtesting.InitCommand(introspectCommand, args); err != nil {
231237
t.Fatal(err)
232238
}

0 commit comments

Comments
 (0)