Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/check-operator/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func isReconcileError(conditions []metav1.Condition) error {
// Run use to run the command.
func (o *Options) Run() error {
o.printOutf("Start checking rolling-update status")
checkFunc := func() (bool, error) {
checkFunc := func(ctx context.Context) (bool, error) {
var agentDone, dcaDone, ccrDone, reconcileError bool
var status common.StatusWrapper
o.printOutf("v2alpha1 is available")
Expand Down Expand Up @@ -213,7 +213,7 @@ func (o *Options) Run() error {
return false, nil
}

return wait.Poll(o.checkPeriod, o.checkTimeout, checkFunc)
return wait.PollUntilContextTimeout(context.Background(), o.checkPeriod, o.checkTimeout, false, checkFunc)
}

func (o *Options) isAgentDone(status *v2alpha1.DaemonSetStatus) bool {
Expand Down
5 changes: 2 additions & 3 deletions cmd/helpers/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -44,7 +43,7 @@ type secretsRequest struct {

// ReadSecrets implements a secrets reader from a directory/mount
func readSecrets(r io.Reader, w io.Writer, dir string) error {
in, err := ioutil.ReadAll(r)
in, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down Expand Up @@ -142,7 +141,7 @@ func readSecretFile(path string) (string, error) {
}

var bytes []byte
bytes, err = ioutil.ReadAll(file)
bytes, err = io.ReadAll(file)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-datadog/agent/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (o *options) execInPod(pod *corev1.Pod, cmd []string, container string) (st
}

var stdout, stderr bytes.Buffer
err = exec.Stream(remotecommand.StreamOptions{
err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{
Stdin: nil,
Stdout: &stdout,
Stderr: &stderr,
Expand Down
5 changes: 2 additions & 3 deletions cmd/kubectl-datadog/flare/flare.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -459,7 +458,7 @@ func (o *options) execInPod(command []string, pod *corev1.Pod) ([]byte, error) {
}

var stdout bytes.Buffer
if err := exec.Stream(remotecommand.StreamOptions{Stdout: &stdout}); err != nil {
if err := exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{Stdout: &stdout}); err != nil {
return []byte{}, err
}

Expand Down Expand Up @@ -524,7 +523,7 @@ func (o *options) sendFlare(archivePath, version string, cmd *cobra.Command) (st
}
}()

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions hack/generate-docs/generate-docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -217,7 +216,7 @@ func mustReadFile(path string) []byte {
}
}()

b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
panic(fmt.Sprintf("cannot read file %q: %s", path, err))
}
Expand Down
19 changes: 13 additions & 6 deletions pkg/controller/utils/datadog/metrics_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ func (mf *metricsForwarder) start(wg *sync.WaitGroup) {

mf.logger.Info("Starting Datadog metrics forwarder")

// wait.PollImmediateUntil is blocking until mf.connectToDatadogAPI returns true or stopChan is closed
// wait.PollImmediateUntil keeps retrying to connect to the Datadog API without returning an error
// wait.PollImmediateUntil returns an error only when stopChan is closed
if err := wait.PollImmediateUntil(mf.retryInterval, mf.connectToDatadogAPI, mf.stopChan); errors.Is(err, wait.ErrWaitTimeout) {
// Create a context that gets cancelled when stopChan is closed
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-mf.stopChan
cancel()
}()

// wait.PollUntilContextCancel is blocking until mf.connectToDatadogAPI returns true or context is cancelled
// wait.PollUntilContextCancel keeps retrying to connect to the Datadog API without returning an error
// wait.PollUntilContextCancel returns an error only when context is cancelled
if err := wait.PollUntilContextCancel(ctx, mf.retryInterval, true, mf.connectToDatadogAPI); errors.Is(err, context.Canceled) {
// stopChan was closed while trying to connect to Datadog API
// The metrics forwarder stopped by the ForwardersManager
mf.logger.Info("Shutting down Datadog metrics forwarder")
Expand Down Expand Up @@ -372,8 +379,8 @@ func (mf *metricsForwarder) setupFromDDAI(ddai *v1alpha1.DatadogAgentInternal) e
}

// connectToDatadogAPI ensures the connection to the Datadog API is valid
// implements wait.ConditionFunc and never returns error to keep retrying
func (mf *metricsForwarder) connectToDatadogAPI() (bool, error) {
// implements wait.ConditionWithContextFunc and never returns error to keep retrying
func (mf *metricsForwarder) connectToDatadogAPI(ctx context.Context) (bool, error) {
var err error
err = mf.setup()

Expand Down
Loading