Skip to content

Commit b98d6ed

Browse files
committed
Merge branch 'bbz/gofmt'
2 parents 194fab8 + c8303c9 commit b98d6ed

File tree

19 files changed

+147
-135
lines changed

19 files changed

+147
-135
lines changed

.github/workflows/matrix-tools.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: AGPL-3.0-only
44

5-
name: Build matrix-tool Docker Images
5+
name: matrix-tools linting and building
66

77
on:
88
pull_request:
@@ -18,6 +18,27 @@ env:
1818
GO_VERSION: "1.24"
1919

2020
jobs:
21+
gofmt:
22+
permissions:
23+
contents: read
24+
packages: read
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
28+
29+
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6
30+
with:
31+
go-version: "${{ env.GO_VERSION }}"
32+
33+
- name: gofmt check
34+
run: |
35+
unformatted_files="$(gofmt -l matrix-tools)"
36+
if [ "$unformatted_files" != "" ]; then
37+
echo "There are .go files that aren't formatted correctly:"
38+
echo "$unformatted_files"
39+
exit 1
40+
fi
41+
2142
tests:
2243
permissions:
2344
contents: read

matrix-tools/cmd/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/element-hq/ess-helm/matrix-tools/internal/pkg/args"
1717
)
1818

19-
2019
func main() {
2120
options, err := args.ParseArgs(os.Args)
2221
if err != nil {

matrix-tools/internal/cmd/deployment-markers/args.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import (
1111
)
1212

1313
const (
14-
FlagSetName = "deployment-markers"
14+
FlagSetName = "deployment-markers"
1515
)
1616

1717
type DeploymentMarkersOptions struct {
18-
Labels map[string]string
18+
Labels map[string]string
1919
DeploymentMarkers []DeploymentMarker
2020
}
2121

22-
2322
type DeploymentMarker struct {
2423
Name string
2524
Key string

matrix-tools/internal/cmd/generate-secrets/args.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ const (
1818

1919
type GenerateSecretsOptions struct {
2020
GeneratedSecrets []GeneratedSecret
21-
Labels map[string]string
21+
Labels map[string]string
2222
}
2323

2424
type GeneratedSecret struct {
25-
ArgValue string
26-
Name string
27-
Key string
28-
Type secret.SecretType
25+
ArgValue string
26+
Name string
27+
Key string
28+
Type secret.SecretType
2929
}
3030

3131
func parseSecretType(value string) (secret.SecretType, error) {
@@ -47,7 +47,6 @@ func parseSecretType(value string) (secret.SecretType, error) {
4747
}
4848
}
4949

50-
5150
func ParseArgs(args []string) (*GenerateSecretsOptions, error) {
5251
var options GenerateSecretsOptions
5352

matrix-tools/internal/cmd/render-config/args.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import (
1010
"strings"
1111
)
1212

13-
1413
const (
15-
FlagSetName = "render-config"
14+
FlagSetName = "render-config"
1615
)
1716

1817
type RenderConfigOptions struct {
19-
Files []string
20-
Output string
18+
Files []string
19+
Output string
2120
}
2221

2322
func ParseArgs(args []string) (*RenderConfigOptions, error) {

matrix-tools/internal/cmd/syn2mas/args.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ const (
1313
FlagSetName = "syn2mas"
1414
)
1515

16-
1716
type Syn2MasOptions struct {
18-
SynapseConfig string
19-
MASConfig string
17+
SynapseConfig string
18+
MASConfig string
2019
}
2120

2221
func ParseArgs(args []string) (*Syn2MasOptions, error) {

matrix-tools/internal/cmd/syn2mas/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"fmt"
99
"os"
1010

11-
"github.com/element-hq/ess-helm/matrix-tools/internal/pkg/util"
1211
executor "github.com/element-hq/ess-helm/matrix-tools/internal/pkg/syn2mas"
12+
"github.com/element-hq/ess-helm/matrix-tools/internal/pkg/util"
1313
)
1414

1515
func Run(options *Syn2MasOptions) {

matrix-tools/internal/pkg/args/args.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ const (
2424
TCPWait
2525
)
2626

27-
2827
type Options struct {
29-
Command CommandType
30-
RenderConfig *renderconfig.RenderConfigOptions
31-
GenerateSecrets *generatesecrets.GenerateSecretsOptions
32-
DeploymentMarkers *deploymentmarkers.DeploymentMarkersOptions
33-
Syn2Mas *syn2mas.Syn2MasOptions
34-
TcpWait *tcpwait.TcpWaitOptions
28+
Command CommandType
29+
RenderConfig *renderconfig.RenderConfigOptions
30+
GenerateSecrets *generatesecrets.GenerateSecretsOptions
31+
DeploymentMarkers *deploymentmarkers.DeploymentMarkersOptions
32+
Syn2Mas *syn2mas.Syn2MasOptions
33+
TcpWait *tcpwait.TcpWaitOptions
3534
}
3635

3736
func ParseArgs(args []string) (*Options, error) {

matrix-tools/internal/pkg/args/args_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
package args
66

77
import (
8-
"testing"
98
"github.com/stretchr/testify/assert"
9+
"testing"
1010

1111
deploymentmarkers "github.com/element-hq/ess-helm/matrix-tools/internal/cmd/deployment-markers"
1212
generatesecrets "github.com/element-hq/ess-helm/matrix-tools/internal/cmd/generate-secrets"
1313
renderconfig "github.com/element-hq/ess-helm/matrix-tools/internal/cmd/render-config"
1414
"github.com/element-hq/ess-helm/matrix-tools/internal/cmd/syn2mas"
15-
"github.com/element-hq/ess-helm/matrix-tools/internal/cmd/tcpwait"
15+
"github.com/element-hq/ess-helm/matrix-tools/internal/cmd/tcpwait"
1616
"github.com/element-hq/ess-helm/matrix-tools/internal/pkg/secret"
1717
)
1818

@@ -33,7 +33,7 @@ func TestParseArgs(t *testing.T) {
3333
name: "Missing --output flag",
3434
args: []string{"cmd", "render-config", "file1"},
3535
expected: &Options{
36-
RenderConfig: &renderconfig.RenderConfigOptions{
36+
RenderConfig: &renderconfig.RenderConfigOptions{
3737
Files: []string{"file1"},
3838
},
3939
},
@@ -50,7 +50,7 @@ func TestParseArgs(t *testing.T) {
5050
args: []string{"cmd", "render-config", "-output", "outputFile", "file1", "file2"},
5151
expected: &Options{
5252
RenderConfig: &renderconfig.RenderConfigOptions{
53-
Files: []string{"file1", "file2"},
53+
Files: []string{"file1", "file2"},
5454
Output: "outputFile",
5555
},
5656
},
@@ -61,7 +61,7 @@ func TestParseArgs(t *testing.T) {
6161
args: []string{"cmd", "render-config", "-output", "outputFile", "file1", "file2"},
6262
expected: &Options{
6363
RenderConfig: &renderconfig.RenderConfigOptions{
64-
Files: []string{"file1", "file2"},
64+
Files: []string{"file1", "file2"},
6565
Output: "outputFile",
6666
},
6767
Command: RenderConfig,
@@ -86,9 +86,9 @@ func TestParseArgs(t *testing.T) {
8686
GenerateSecrets: &generatesecrets.GenerateSecretsOptions{
8787
GeneratedSecrets: []generatesecrets.GeneratedSecret{
8888
{ArgValue: "secret1:value1:rand32", Name: "secret1", Key: "value1", Type: secret.Rand32},
89-
},
90-
Labels: map[string]string{"app.kubernetes.io/managed-by":"matrix-tools-init-secrets", "mykey":"myval"},
9189
},
90+
Labels: map[string]string{"app.kubernetes.io/managed-by": "matrix-tools-init-secrets", "mykey": "myval"},
91+
},
9292
Command: GenerateSecrets,
9393
},
9494
err: false,
@@ -103,7 +103,7 @@ func TestParseArgs(t *testing.T) {
103103
{ArgValue: "secret1:value1:rand32", Name: "secret1", Key: "value1", Type: secret.Rand32},
104104
{ArgValue: "secret2:value2:signingkey", Name: "secret2", Key: "value2", Type: secret.SigningKey},
105105
},
106-
Labels: map[string]string{"app.kubernetes.io/managed-by":"matrix-tools-init-secrets"},
106+
Labels: map[string]string{"app.kubernetes.io/managed-by": "matrix-tools-init-secrets"},
107107
},
108108
Command: GenerateSecrets,
109109
},
@@ -132,7 +132,7 @@ func TestParseArgs(t *testing.T) {
132132
{Name: "cm1", Key: "key1", Step: "pre", NewValue: "value1", AllowedValues: []string{"value1"}},
133133
{Name: "cm1", Key: "key2", Step: "pre", NewValue: "value2", AllowedValues: []string{"value1", "value2"}},
134134
},
135-
Labels: map[string]string{"app.kubernetes.io/managed-by":"matrix-tools-deployment-markers"},
135+
Labels: map[string]string{"app.kubernetes.io/managed-by": "matrix-tools-deployment-markers"},
136136
},
137137
Command: DeploymentMarkers,
138138
},
@@ -147,14 +147,13 @@ func TestParseArgs(t *testing.T) {
147147
{Name: "cm1", Key: "key1", Step: "post", NewValue: "value1", AllowedValues: []string{"value1"}},
148148
{Name: "cm1", Key: "key2", Step: "post", NewValue: "value2", AllowedValues: []string{"value1", "value2"}},
149149
},
150-
Labels: map[string]string{"app.kubernetes.io/managed-by":"matrix-tools-deployment-markers"},
150+
Labels: map[string]string{"app.kubernetes.io/managed-by": "matrix-tools-deployment-markers"},
151151
},
152152
Command: DeploymentMarkers,
153153
},
154154
err: false,
155155
},
156156

157-
158157
{
159158
name: "Invalid secret type",
160159
args: []string{"cmd", "generate-secrets", "-secrets", "secret1:value1:unknown"},
@@ -170,30 +169,30 @@ func TestParseArgs(t *testing.T) {
170169
},
171170

172171
{
173-
name: "Proper syntax of syn2mas",
174-
args: []string{"cmd", "syn2mas", "-config", "file1", "-synapse-config", "file2"},
172+
name: "Proper syntax of syn2mas",
173+
args: []string{"cmd", "syn2mas", "-config", "file1", "-synapse-config", "file2"},
175174
expected: &Options{
176175
Syn2Mas: &syn2mas.Syn2MasOptions{
177-
MASConfig: "file1",
176+
MASConfig: "file1",
178177
SynapseConfig: "file2",
179178
},
180179
Command: Syn2Mas,
181180
},
182-
err: false,
181+
err: false,
183182
},
184183
{
185-
name: "Wrong syntax of syn2mas",
186-
args: []string{"cmd", "syn2mas"},
184+
name: "Wrong syntax of syn2mas",
185+
args: []string{"cmd", "syn2mas"},
187186
expected: &Options{
188187
Command: Syn2Mas,
189188
},
190-
err: true,
189+
err: true,
191190
},
192191
}
193192

194193
for _, tc := range testCases {
195194
t.Run(tc.name, func(t *testing.T) {
196-
options, err := ParseArgs(tc.args);
195+
options, err := ParseArgs(tc.args)
197196
if tc.err {
198197
assert.Error(t, err)
199198
assert.Nil(t, options)

matrix-tools/internal/pkg/marker/marker.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,28 @@ func GenerateConfigMap(client kubernetes.Interface, labels map[string]string, na
5252

5353
currentValueIsAllowed := false
5454
switch step {
55-
case "pre":
56-
// During pre-install, we check if the current value is in the allowed values
57-
// If it is not, it means the state of the deployment will not support the helm upgrade
58-
// and the upgrade will fail
59-
if _, ok := existingConfigMap.Data[key]; ok {
60-
for _, allowed := range allowedValues {
61-
if string(existingConfigMap.Data[key]) == allowed {
62-
fmt.Printf("Existing value: %s", string(existingConfigMap.Data[key]))
63-
currentValueIsAllowed = true
64-
break
65-
}
66-
}
67-
if !currentValueIsAllowed {
68-
return fmt.Errorf("%s marker prevented transitioning to value %s from value %s because it is not in the allowed values : %s", key, newValue, string(existingConfigMap.Data[key]), strings.Join(allowedValues, ", "))
55+
case "pre":
56+
// During pre-install, we check if the current value is in the allowed values
57+
// If it is not, it means the state of the deployment will not support the helm upgrade
58+
// and the upgrade will fail
59+
if _, ok := existingConfigMap.Data[key]; ok {
60+
for _, allowed := range allowedValues {
61+
if string(existingConfigMap.Data[key]) == allowed {
62+
fmt.Printf("Existing value: %s", string(existingConfigMap.Data[key]))
63+
currentValueIsAllowed = true
64+
break
6965
}
7066
}
71-
case "post":
72-
// During post-install, we update the configmap with the new value as the upgrade succeeded
73-
existingConfigMap.Data[key] = newValue
74-
default:
75-
return fmt.Errorf("unknown step: %s", step)
67+
if !currentValueIsAllowed {
68+
return fmt.Errorf("%s marker prevented transitioning to value %s from value %s because it is not in the allowed values : %s", key, newValue, string(existingConfigMap.Data[key]), strings.Join(allowedValues, ", "))
69+
}
7670
}
71+
case "post":
72+
// During post-install, we update the configmap with the new value as the upgrade succeeded
73+
existingConfigMap.Data[key] = newValue
74+
default:
75+
return fmt.Errorf("unknown step: %s", step)
76+
}
7777

7878
_, err = configMapsClient.Update(ctx, existingConfigMap, metav1.UpdateOptions{})
7979
if err != nil {

0 commit comments

Comments
 (0)