forked from juju/juju
/
steps_27.go
157 lines (145 loc) · 4.65 KB
/
steps_27.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package upgrades
import (
"os"
"path/filepath"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/DavinZhang/juju/agent"
k8sconstants "github.com/DavinZhang/juju/caas/kubernetes/provider/constants"
"github.com/DavinZhang/juju/core/paths"
)
// stateStepsFor27 returns upgrade steps for Juju 2.7.0.
func stateStepsFor27() []Step {
return []Step{
&upgradeStep{
description: "add controller node docs",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddControllerNodeDocs()
},
},
&upgradeStep{
description: "recreate spaces with IDs",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddSpaceIdToSpaceDocs()
},
},
&upgradeStep{
description: "change subnet AvailabilityZone to AvailabilityZones",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().ChangeSubnetAZtoSlice()
},
},
&upgradeStep{
description: "change subnet SpaceName to SpaceID",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().ChangeSubnetSpaceNameToSpaceID()
},
},
&upgradeStep{
description: "recreate subnets with IDs",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().AddSubnetIdToSubnetDocs()
},
},
&upgradeStep{
description: "replace portsDoc.SubnetID as a CIDR with an ID.",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().ReplacePortsDocSubnetIDCIDR()
},
},
&upgradeStep{
description: "ensure application settings exist for all relations",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().EnsureRelationApplicationSettings()
},
},
&upgradeStep{
description: "ensure stored addresses refer to space by ID, and remove old space name/provider ID",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().ConvertAddressSpaceIDs()
},
},
&upgradeStep{
description: "replace space name in endpointBindingDoc bindings with an space ID",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().ReplaceSpaceNameWithIDEndpointBindings()
},
},
&upgradeStep{
description: `ensure model config for default-space is "" if either absent or is set to "_default"`,
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().EnsureDefaultSpaceSetting()
},
},
&upgradeStep{
description: "remove controller config for max-logs-age and max-logs-size if set",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().RemoveControllerConfigMaxLogAgeAndSize()
},
},
}
}
// stepsFor27 returns upgrade steps for Juju 2.7.
func stepsFor27() []Step {
return []Step{
&upgradeStep{
description: "change owner of unit and machine logs to adm",
targets: []Target{AllMachines},
run: resetLogPermissions,
},
}
}
func setJujuFolderPermissionsToAdm(dir string) error {
wantedOwner, wantedGroup := paths.SyslogUserGroup()
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return errors.Trace(err)
}
if info.IsDir() {
return nil
}
if err := paths.SetOwnership(path, wantedOwner, wantedGroup); err != nil {
return errors.Trace(err)
}
if err := os.Chmod(path, paths.LogfilePermission); err != nil {
return errors.Trace(err)
}
return nil
})
if err != nil {
return errors.Trace(err)
}
logger.Infof("Successfully changed permissions of dir %q", dir)
return nil
}
// We rewrite/reset the systemd files and change the existing log file permissions
func resetLogPermissions(context Context) error {
tag := context.AgentConfig().Tag()
if tag.Kind() != names.MachineTagKind {
logger.Infof("skipping agent %q, not a machine", tag.String())
return nil
}
// For now a CAAS cannot be machineTagKind so it will not come as far as here for k8.
// But to make sure for future refactoring, which are planned, we check here as well.
if context.AgentConfig().Value(agent.ProviderType) == k8sconstants.CAASProviderType {
logger.Infof("skipping agent %q, is CAAS", k8sconstants.CAASProviderType)
return nil
}
if err := writeServiceFiles(false)(context); err != nil {
return errors.Trace(err)
}
return errors.Trace(setJujuFolderPermissionsToAdm(context.AgentConfig().LogDir()))
}