Skip to content

Commit 5f1fe30

Browse files
authored
Merge pull request #4329 from fluxcd/tidy-nits
Address various issues throughout code base
2 parents ac95ac0 + f137263 commit 5f1fe30

Some content is hidden

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

43 files changed

+169
-160
lines changed

cmd/flux/create.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func (names apiType) upsertAndWait(object upsertWaitable, mutate func() error) e
131131
}
132132

133133
logger.Waitingf("waiting for %s reconciliation", names.kind)
134-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
135-
isReady(ctx, kubeClient, namespacedName, object)); err != nil {
134+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
135+
isReady(kubeClient, namespacedName, object)); err != nil {
136136
return err
137137
}
138138
logger.Successf("%s reconciliation completed", names.kind)
@@ -165,6 +165,6 @@ func parseLabels() (map[string]string, error) {
165165
}
166166

167167
func validateObjectName(name string) bool {
168-
r := regexp.MustCompile("^[a-z0-9]([a-z0-9\\-]){0,61}[a-z0-9]$")
168+
r := regexp.MustCompile(`^[a-z0-9]([a-z0-9\-]){0,61}[a-z0-9]$`)
169169
return r.MatchString(name)
170170
}

cmd/flux/create_alert.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
132132
}
133133

134134
logger.Waitingf("waiting for Alert reconciliation")
135-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
136-
isAlertReady(ctx, kubeClient, namespacedName, &alert)); err != nil {
135+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
136+
isAlertReady(kubeClient, namespacedName, &alert)); err != nil {
137137
return err
138138
}
139139
logger.Successf("Alert %s is ready", name)
@@ -171,9 +171,8 @@ func upsertAlert(ctx context.Context, kubeClient client.Client,
171171
return namespacedName, nil
172172
}
173173

174-
func isAlertReady(ctx context.Context, kubeClient client.Client,
175-
namespacedName types.NamespacedName, alert *notificationv1b2.Alert) wait.ConditionFunc {
176-
return func() (bool, error) {
174+
func isAlertReady(kubeClient client.Client, namespacedName types.NamespacedName, alert *notificationv1b2.Alert) wait.ConditionWithContextFunc {
175+
return func(ctx context.Context) (bool, error) {
177176
err := kubeClient.Get(ctx, namespacedName, alert)
178177
if err != nil {
179178
return false, err

cmd/flux/create_alertprovider.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
127127
}
128128

129129
logger.Waitingf("waiting for Provider reconciliation")
130-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
131-
isAlertProviderReady(ctx, kubeClient, namespacedName, &provider)); err != nil {
130+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
131+
isAlertProviderReady(kubeClient, namespacedName, &provider)); err != nil {
132132
return err
133133
}
134134

@@ -168,9 +168,8 @@ func upsertAlertProvider(ctx context.Context, kubeClient client.Client,
168168
return namespacedName, nil
169169
}
170170

171-
func isAlertProviderReady(ctx context.Context, kubeClient client.Client,
172-
namespacedName types.NamespacedName, provider *notificationv1.Provider) wait.ConditionFunc {
173-
return func() (bool, error) {
171+
func isAlertProviderReady(kubeClient client.Client, namespacedName types.NamespacedName, provider *notificationv1.Provider) wait.ConditionWithContextFunc {
172+
return func(ctx context.Context) (bool, error) {
174173
err := kubeClient.Get(ctx, namespacedName, provider)
175174
if err != nil {
176175
return false, err

cmd/flux/create_helmrelease.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
303303
}
304304

305305
logger.Waitingf("waiting for HelmRelease reconciliation")
306-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
307-
isHelmReleaseReady(ctx, kubeClient, namespacedName, &helmRelease)); err != nil {
306+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
307+
isHelmReleaseReady(kubeClient, namespacedName, &helmRelease)); err != nil {
308308
return err
309309
}
310310
logger.Successf("HelmRelease %s is ready", name)
@@ -344,9 +344,8 @@ func upsertHelmRelease(ctx context.Context, kubeClient client.Client,
344344
return namespacedName, nil
345345
}
346346

347-
func isHelmReleaseReady(ctx context.Context, kubeClient client.Client,
348-
namespacedName types.NamespacedName, helmRelease *helmv2.HelmRelease) wait.ConditionFunc {
349-
return func() (bool, error) {
347+
func isHelmReleaseReady(kubeClient client.Client, namespacedName types.NamespacedName, helmRelease *helmv2.HelmRelease) wait.ConditionWithContextFunc {
348+
return func(ctx context.Context) (bool, error) {
350349
err := kubeClient.Get(ctx, namespacedName, helmRelease)
351350
if err != nil {
352351
return false, err

cmd/flux/create_image_policy.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ the status of the object.`),
5454
RunE: createImagePolicyRun}
5555

5656
type imagePolicyFlags struct {
57-
imageRef string
58-
semver string
59-
alpha string
60-
numeric string
61-
filterRegex string
62-
filterExtract string
63-
filterNumerical string
57+
imageRef string
58+
semver string
59+
alpha string
60+
numeric string
61+
filterRegex string
62+
filterExtract string
6463
}
6564

6665
var imagePolicyArgs = imagePolicyFlags{}
@@ -183,7 +182,6 @@ func validateExtractStr(template string, capNames []string) error {
183182
name, num, rest, ok := extract(template)
184183
if !ok {
185184
// Malformed extract string, assume user didn't want this
186-
template = template[1:]
187185
return fmt.Errorf("--filter-extract is malformed")
188186
}
189187
template = rest

cmd/flux/create_kustomization.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
263263
}
264264

265265
logger.Waitingf("waiting for Kustomization reconciliation")
266-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
267-
isKustomizationReady(ctx, kubeClient, namespacedName, &kustomization)); err != nil {
266+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
267+
isKustomizationReady(kubeClient, namespacedName, &kustomization)); err != nil {
268268
return err
269269
}
270270
logger.Successf("Kustomization %s is ready", name)
@@ -304,9 +304,8 @@ func upsertKustomization(ctx context.Context, kubeClient client.Client,
304304
return namespacedName, nil
305305
}
306306

307-
func isKustomizationReady(ctx context.Context, kubeClient client.Client,
308-
namespacedName types.NamespacedName, kustomization *kustomizev1.Kustomization) wait.ConditionFunc {
309-
return func() (bool, error) {
307+
func isKustomizationReady(kubeClient client.Client, namespacedName types.NamespacedName, kustomization *kustomizev1.Kustomization) wait.ConditionWithContextFunc {
308+
return func(ctx context.Context) (bool, error) {
310309
err := kubeClient.Get(ctx, namespacedName, kustomization)
311310
if err != nil {
312311
return false, err

cmd/flux/create_receiver.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error {
139139
}
140140

141141
logger.Waitingf("waiting for Receiver reconciliation")
142-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
143-
isReceiverReady(ctx, kubeClient, namespacedName, &receiver)); err != nil {
142+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
143+
isReceiverReady(kubeClient, namespacedName, &receiver)); err != nil {
144144
return err
145145
}
146146
logger.Successf("Receiver %s is ready", name)
@@ -180,9 +180,8 @@ func upsertReceiver(ctx context.Context, kubeClient client.Client,
180180
return namespacedName, nil
181181
}
182182

183-
func isReceiverReady(ctx context.Context, kubeClient client.Client,
184-
namespacedName types.NamespacedName, receiver *notificationv1.Receiver) wait.ConditionFunc {
185-
return func() (bool, error) {
183+
func isReceiverReady(kubeClient client.Client, namespacedName types.NamespacedName, receiver *notificationv1.Receiver) wait.ConditionWithContextFunc {
184+
return func(ctx context.Context) (bool, error) {
186185
err := kubeClient.Get(ctx, namespacedName, receiver)
187186
if err != nil {
188187
return false, err

cmd/flux/create_source_bucket.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
204204
}
205205

206206
logger.Waitingf("waiting for Bucket source reconciliation")
207-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
208-
isBucketReady(ctx, kubeClient, namespacedName, bucket)); err != nil {
207+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
208+
isBucketReady(kubeClient, namespacedName, bucket)); err != nil {
209209
return err
210210
}
211211
logger.Successf("Bucket source reconciliation completed")
@@ -248,9 +248,8 @@ func upsertBucket(ctx context.Context, kubeClient client.Client,
248248
return namespacedName, nil
249249
}
250250

251-
func isBucketReady(ctx context.Context, kubeClient client.Client,
252-
namespacedName types.NamespacedName, bucket *sourcev1.Bucket) wait.ConditionFunc {
253-
return func() (bool, error) {
251+
func isBucketReady(kubeClient client.Client, namespacedName types.NamespacedName, bucket *sourcev1.Bucket) wait.ConditionWithContextFunc {
252+
return func(ctx context.Context) (bool, error) {
254253
err := kubeClient.Get(ctx, namespacedName, bucket)
255254
if err != nil {
256255
return false, err

cmd/flux/create_source_git.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
325325
}
326326

327327
logger.Waitingf("waiting for GitRepository source reconciliation")
328-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
329-
isGitRepositoryReady(ctx, kubeClient, namespacedName, &gitRepository)); err != nil {
328+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
329+
isGitRepositoryReady(kubeClient, namespacedName, &gitRepository)); err != nil {
330330
return err
331331
}
332332
logger.Successf("GitRepository source reconciliation completed")
@@ -369,9 +369,8 @@ func upsertGitRepository(ctx context.Context, kubeClient client.Client,
369369
return namespacedName, nil
370370
}
371371

372-
func isGitRepositoryReady(ctx context.Context, kubeClient client.Client,
373-
namespacedName types.NamespacedName, gitRepository *sourcev1.GitRepository) wait.ConditionFunc {
374-
return func() (bool, error) {
372+
func isGitRepositoryReady(kubeClient client.Client, namespacedName types.NamespacedName, gitRepository *sourcev1.GitRepository) wait.ConditionWithContextFunc {
373+
return func(ctx context.Context) (bool, error) {
375374
err := kubeClient.Get(ctx, namespacedName, gitRepository)
376375
if err != nil {
377376
return false, err

cmd/flux/create_source_helm.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
231231
}
232232

233233
logger.Waitingf("waiting for HelmRepository source reconciliation")
234-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
235-
isHelmRepositoryReady(ctx, kubeClient, namespacedName, helmRepository)); err != nil {
234+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
235+
isHelmRepositoryReady(kubeClient, namespacedName, helmRepository)); err != nil {
236236
return err
237237
}
238238
logger.Successf("HelmRepository source reconciliation completed")
@@ -280,9 +280,8 @@ func upsertHelmRepository(ctx context.Context, kubeClient client.Client,
280280
return namespacedName, nil
281281
}
282282

283-
func isHelmRepositoryReady(ctx context.Context, kubeClient client.Client,
284-
namespacedName types.NamespacedName, helmRepository *sourcev1.HelmRepository) wait.ConditionFunc {
285-
return func() (bool, error) {
283+
func isHelmRepositoryReady(kubeClient client.Client, namespacedName types.NamespacedName, helmRepository *sourcev1.HelmRepository) wait.ConditionWithContextFunc {
284+
return func(ctx context.Context) (bool, error) {
286285
err := kubeClient.Get(ctx, namespacedName, helmRepository)
287286
if err != nil {
288287
return false, err

cmd/flux/create_source_oci.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ func createSourceOCIRepositoryCmdRun(cmd *cobra.Command, args []string) error {
192192
}
193193

194194
logger.Waitingf("waiting for OCIRepository reconciliation")
195-
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
196-
isOCIRepositoryReady(ctx, kubeClient, namespacedName, repository)); err != nil {
195+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
196+
isOCIRepositoryReady(kubeClient, namespacedName, repository)); err != nil {
197197
return err
198198
}
199199
logger.Successf("OCIRepository reconciliation completed")
@@ -236,9 +236,8 @@ func upsertOCIRepository(ctx context.Context, kubeClient client.Client,
236236
return namespacedName, nil
237237
}
238238

239-
func isOCIRepositoryReady(ctx context.Context, kubeClient client.Client,
240-
namespacedName types.NamespacedName, ociRepository *sourcev1.OCIRepository) wait.ConditionFunc {
241-
return func() (bool, error) {
239+
func isOCIRepositoryReady(kubeClient client.Client, namespacedName types.NamespacedName, ociRepository *sourcev1.OCIRepository) wait.ConditionWithContextFunc {
240+
return func(ctx context.Context) (bool, error) {
242241
err := kubeClient.Get(ctx, namespacedName, ociRepository)
243242
if err != nil {
244243
return false, err

cmd/flux/export_secret.go

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type exportableWithSecretList interface {
4646
}
4747

4848
type exportWithSecretCommand struct {
49-
apiType
5049
object exportableWithSecret
5150
list exportableWithSecretList
5251
}

cmd/flux/get_alert.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package main
1919
import (
2020
"fmt"
2121
"strconv"
22-
"strings"
2322

2423
"github.com/spf13/cobra"
24+
"golang.org/x/text/cases"
25+
"golang.org/x/text/language"
2526
"k8s.io/apimachinery/pkg/runtime"
2627

2728
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
@@ -77,7 +78,8 @@ func init() {
7778
func (s alertListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
7879
item := s.Items[i]
7980
status, msg := statusAndMessage(item.Status.Conditions)
80-
return append(nameColumns(&item, includeNamespace, includeKind), strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
81+
return append(nameColumns(&item, includeNamespace, includeKind),
82+
cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
8183
}
8284

8385
func (s alertListAdapter) headers(includeNamespace bool) []string {

cmd/flux/get_helmrelease.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package main
1919
import (
2020
"fmt"
2121
"strconv"
22-
"strings"
2322

24-
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
2523
"github.com/spf13/cobra"
24+
"golang.org/x/text/cases"
25+
"golang.org/x/text/language"
2626
"k8s.io/apimachinery/pkg/runtime"
27+
28+
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
2729
)
2830

2931
var getHelmReleaseCmd = &cobra.Command{
@@ -75,7 +77,7 @@ func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool, incl
7577
revision := item.Status.LastAppliedRevision
7678
status, msg := statusAndMessage(item.Status.Conditions)
7779
return append(nameColumns(&item, includeNamespace, includeKind),
78-
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
80+
revision, cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
7981
}
8082

8183
func (a helmReleaseListAdapter) headers(includeNamespace bool) []string {

cmd/flux/get_image_repository.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ package main
1919
import (
2020
"fmt"
2121
"strconv"
22-
"strings"
2322
"time"
2423

2524
"github.com/spf13/cobra"
25+
"golang.org/x/text/cases"
26+
"golang.org/x/text/language"
2627
"k8s.io/apimachinery/pkg/runtime"
2728

2829
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
@@ -82,7 +83,7 @@ func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
8283
lastScan = item.Status.LastScanResult.ScanTime.Time.Format(time.RFC3339)
8384
}
8485
return append(nameColumns(&item, includeNamespace, includeKind),
85-
lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
86+
lastScan, cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
8687
}
8788

8889
func (s imageRepositoryListAdapter) headers(includeNamespace bool) []string {

cmd/flux/get_image_update.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ package main
1919
import (
2020
"fmt"
2121
"strconv"
22-
"strings"
2322
"time"
2423

2524
"github.com/spf13/cobra"
25+
"golang.org/x/text/cases"
26+
"golang.org/x/text/language"
2627
"k8s.io/apimachinery/pkg/runtime"
2728

2829
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
@@ -81,7 +82,8 @@ func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace
8182
if item.Status.LastAutomationRunTime != nil {
8283
lastRun = item.Status.LastAutomationRunTime.Time.Format(time.RFC3339)
8384
}
84-
return append(nameColumns(&item, includeNamespace, includeKind), lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
85+
return append(nameColumns(&item, includeNamespace, includeKind), lastRun,
86+
cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
8587
}
8688

8789
func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []string {

cmd/flux/get_kustomization.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package main
1919
import (
2020
"fmt"
2121
"strconv"
22-
"strings"
2322

2423
"github.com/spf13/cobra"
24+
"golang.org/x/text/cases"
25+
"golang.org/x/text/language"
2526
"k8s.io/apimachinery/pkg/runtime"
2627

2728
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
@@ -83,7 +84,7 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in
8384
revision = utils.TruncateHex(revision)
8485
msg = utils.TruncateHex(msg)
8586
return append(nameColumns(&item, includeNamespace, includeKind),
86-
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
87+
revision, cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
8788
}
8889

8990
func (a kustomizationListAdapter) headers(includeNamespace bool) []string {

cmd/flux/get_receiver.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package main
1919
import (
2020
"fmt"
2121
"strconv"
22-
"strings"
2322

2423
"github.com/spf13/cobra"
24+
"golang.org/x/text/cases"
25+
"golang.org/x/text/language"
2526
"k8s.io/apimachinery/pkg/runtime"
2627

2728
notificationv1 "github.com/fluxcd/notification-controller/api/v1"
@@ -74,7 +75,8 @@ func init() {
7475
func (s receiverListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
7576
item := s.Items[i]
7677
status, msg := statusAndMessage(item.Status.Conditions)
77-
return append(nameColumns(&item, includeNamespace, includeKind), strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
78+
return append(nameColumns(&item, includeNamespace, includeKind),
79+
cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
7880
}
7981

8082
func (s receiverListAdapter) headers(includeNamespace bool) []string {

0 commit comments

Comments
 (0)