Skip to content

Commit

Permalink
Docker authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatur authored Nov 3, 2020
1 parent 3ebe16a commit 828353e
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
"noctx", # Too strict
"exhaustive", # Too strict
"nlreturn", # Too strict
"wrapcheck",
"exhaustivestruct",
"tparallel",
]

[issues]
Expand Down
21 changes: 10 additions & 11 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ fail_fast:
stop:
when: "branch != 'master'"

global_job_config:
secrets:
- name: dockerhub-pull-secrets
prologue:
commands:
- curl -sSfL https://raw.githubusercontent.com/ldez/semgo/master/godownloader.sh | sudo sh -s -- -b "/usr/local/bin"
- sudo semgo go1.15
- echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
- checkout

blocks:
- name: Build
skip:
when: "branch = 'gh-pages'"
task:
prologue:
commands:
- curl -sSfL https://raw.githubusercontent.com/ldez/semgo/master/godownloader.sh | sudo sh -s -- -b "/usr/local/bin"
- sudo semgo go1.15
- checkout
jobs:
- name: Cache Go dependencies
commands:
Expand All @@ -43,9 +48,6 @@ blocks:
task:
prologue:
commands:
- curl -sSfL https://raw.githubusercontent.com/ldez/semgo/master/godownloader.sh | sudo sh -s -- -b "/usr/local/bin"
- sudo semgo go1.15
- checkout
- cache restore
jobs:
- name: Unit Tests
Expand All @@ -58,9 +60,6 @@ blocks:
task:
prologue:
commands:
- curl -sSfL https://raw.githubusercontent.com/ldez/semgo/master/godownloader.sh | sudo sh -s -- -b "/usr/local/bin"
- sudo semgo go1.15
- checkout
- cache restore
- cache restore traefik-mesh-dist-$SEMAPHORE_GIT_BRANCH-$SEMAPHORE_WORKFLOW_ID
- cache restore traefik-mesh-img-$SEMAPHORE_GIT_BRANCH-$SEMAPHORE_WORKFLOW_ID
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ WORKDIR /go/src/github.com/traefik/mesh
RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh

# Download golangci-lint binary to bin folder in $GOPATH
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.31.0
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.32.0

ENV GO111MODULE on
COPY go.mod go.sum ./
Expand Down
3 changes: 2 additions & 1 deletion cmd/mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"fmt"
stdlog "log"
"net/http"
Expand Down Expand Up @@ -119,7 +120,7 @@ func traefikMeshCommand(config *cmd.TraefikMeshConfiguration) error {
go func() {
defer wg.Done()

if err := apiServer.ListenAndServe(); err != http.ErrServerClosed {
if err := apiServer.ListenAndServe(); errors.Is(err, http.ErrServerClosed) {
apiErrCh <- fmt.Errorf("API server has stopped unexpectedly: %w", err)
}
}()
Expand Down
12 changes: 6 additions & 6 deletions integration/k3d/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewCluster(logger logrus.FieldLogger, masterURL string, name string, opts .
}

if err = createCluster(logger, name, clusterOpts.Cmd); err != nil {
return nil, fmt.Errorf("unable to create k3s cluster: %d", err)
return nil, fmt.Errorf("unable to create k3s cluster: %w", err)
}

if err = importDockerImages(logger, name, clusterOpts.Images); err != nil {
Expand Down Expand Up @@ -199,7 +199,7 @@ func (c *Cluster) WaitReadyDeployment(name, namespace string, timeout time.Durat
return fmt.Errorf("deployment %q has not been yet created", name)
}

return fmt.Errorf("unable get deployment %q in namespace %q: %v", name, namespace, err)
return fmt.Errorf("unable get deployment %q in namespace %q: %w", name, namespace, err)
}

if d.Status.UpdatedReplicas == *(d.Spec.Replicas) &&
Expand Down Expand Up @@ -230,7 +230,7 @@ func (c *Cluster) WaitReadyDaemonSet(name, namespace string, timeout time.Durati
return fmt.Errorf("daemonset %q has not been yet created", name)
}

return fmt.Errorf("unable get daemonset %q in namespace %q: %v", name, namespace, err)
return fmt.Errorf("unable get daemonset %q in namespace %q: %w", name, namespace, err)
}
if d.Status.NumberReady == d.Status.DesiredNumberScheduled {
return nil
Expand All @@ -257,7 +257,7 @@ func (c *Cluster) WaitReadyPod(name, namespace string, timeout time.Duration) er
return fmt.Errorf("pod %q has not been yet created", name)
}

return fmt.Errorf("unable get pod %q in namespace %q: %v", name, namespace, err)
return fmt.Errorf("unable get pod %q in namespace %q: %w", name, namespace, err)
}

if !isPodReady(pod) {
Expand Down Expand Up @@ -370,11 +370,11 @@ func createK8sClient(logger logrus.FieldLogger, clusterName, masterURL string) (
err = try.Retry(func() error {
client, err = k8s.NewClient(logger, masterURL, kubeConfigPath)
if err != nil {
return fmt.Errorf("unable to create clients: %v", err)
return fmt.Errorf("unable to create clients: %w", err)
}

if _, err = client.KubernetesClient().Discovery().ServerVersion(); err != nil {
return fmt.Errorf("unable to get server version: %v", err)
return fmt.Errorf("unable to get server version: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion integration/try/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func BodyContains(values ...string) ResponseCondition {
return func(res *http.Response) error {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %s", err)
return fmt.Errorf("failed to read response body: %w", err)
}

for _, value := range values {
Expand Down
2 changes: 1 addition & 1 deletion integration/try/try.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Retry(f func() error, timeout time.Duration) error {
ebo.MaxElapsedTime = applyCIMultiplier(timeout)

if err := backoff.Retry(safe.OperationWithRecover(f), ebo); err != nil {
return fmt.Errorf("unable execute function: %v", err)
return fmt.Errorf("unable execute function: %w", err)
}

return nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/annotations/annotations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package annotations

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -154,7 +155,7 @@ func TestGetRetryAttempts(t *testing.T) {
attempts, err := GetRetryAttempts(test.annotations)
if test.err {
require.Error(t, err)
assert.Equal(t, test.wantNotFound, err == ErrNotFound)
assert.Equal(t, test.wantNotFound, errors.Is(err, ErrNotFound))
return
}

Expand Down Expand Up @@ -192,7 +193,7 @@ func TestGetCircuitBreakerExpression(t *testing.T) {
value, err := GetCircuitBreakerExpression(test.annotations)
if test.err {
require.Error(t, err)
assert.Equal(t, test.wantNotFound, err == ErrNotFound)
assert.Equal(t, test.wantNotFound, errors.Is(err, ErrNotFound))
return
}

Expand Down Expand Up @@ -237,7 +238,7 @@ func TestGetRateLimitBurst(t *testing.T) {
value, err := GetRateLimitBurst(test.annotations)
if test.err {
require.Error(t, err)
assert.Equal(t, test.wantNotFound, err == ErrNotFound)
assert.Equal(t, test.wantNotFound, errors.Is(err, ErrNotFound))
return
}

Expand Down Expand Up @@ -282,7 +283,7 @@ func TestGetRateLimitAverage(t *testing.T) {
value, err := GetRateLimitAverage(test.annotations)
if test.err {
require.Error(t, err)
assert.Equal(t, test.wantNotFound, err == ErrNotFound)
assert.Equal(t, test.wantNotFound, errors.Is(err, ErrNotFound))
return
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/annotations/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func buildRetryMiddleware(annotations map[string]string) (middleware *dynamic.Mi

retryAttempts, err = GetRetryAttempts(annotations)
if err != nil {
if err == ErrNotFound {
if errors.Is(err, ErrNotFound) {
return nil, "", nil
}

Expand All @@ -60,14 +60,14 @@ func buildRateLimitMiddleware(annotations map[string]string) (middleware *dynami
)

rateLimitBurst, err = GetRateLimitBurst(annotations)
if err == ErrNotFound {
if errors.Is(err, ErrNotFound) {
return nil, "", nil
} else if err != nil {
return nil, "", fmt.Errorf("unable to build rate-limit middleware: %w", err)
}

rateLimitAverage, err = GetRateLimitAverage(annotations)
if err == ErrNotFound {
if errors.Is(err, ErrNotFound) {
return nil, "", nil
} else if err != nil {
return nil, "", fmt.Errorf("unable to build rate-limit middleware: %w", err)
Expand All @@ -93,7 +93,7 @@ func buildCircuitBreakerMiddleware(annotations map[string]string) (middleware *d

circuitBreakerExpression, err = GetCircuitBreakerExpression(annotations)
if err != nil {
if err == ErrNotFound {
if errors.Is(err, ErrNotFound) {
return nil, "", nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func buildKubernetesClient(log logrus.FieldLogger, config *rest.Config) (*kubern

client, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("unable to create kubernetes client: %v", err)
return nil, fmt.Errorf("unable to create kubernetes client: %w", err)
}

return client, nil
Expand All @@ -121,7 +121,7 @@ func buildSmiAccessClient(log logrus.FieldLogger, config *rest.Config) (*accessc

client, err := accessclient.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("unable to create SMI Access Client: %v", err)
return nil, fmt.Errorf("unable to create SMI Access Client: %w", err)
}

return client, nil
Expand All @@ -133,7 +133,7 @@ func buildSmiSpecsClient(log logrus.FieldLogger, config *rest.Config) (*specscli

client, err := specsclient.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("unable to create SMI Specs Client: %v", err)
return nil, fmt.Errorf("unable to create SMI Specs Client: %w", err)
}

return client, nil
Expand All @@ -145,7 +145,7 @@ func buildSmiSplitClient(log logrus.FieldLogger, config *rest.Config) (*splitcli

client, err := splitclient.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("unable to create SMI Split Client: %v", err)
return nil, fmt.Errorf("unable to create SMI Split Client: %w", err)
}

return client, nil
Expand Down
24 changes: 12 additions & 12 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *Provider) BuildConfig(t *topology.Topology) *dynamic.Configuration {

for svcKey, svc := range t.Services {
if err := p.buildConfigForService(t, cfg, svc); err != nil {
err = fmt.Errorf("unable to build configuration: %v", err)
err = fmt.Errorf("unable to build configuration: %w", err)
svc.AddError(err)
p.logger.Errorf("Error building dynamic configuration for Service %q: %v", svcKey, err)
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (p *Provider) buildConfigForService(t *topology.Topology, cfg *dynamic.Conf

for _, tsKey := range svc.TrafficSplits {
if err := p.buildServiceAndRoutersForTrafficSplit(t, cfg, tsKey, scheme, trafficType, middlewareKeys); err != nil {
err = fmt.Errorf("unable to build routers and services : %v", err)
err = fmt.Errorf("unable to build routers and services : %w", err)
t.TrafficSplits[tsKey].AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficSplit %q: %v", tsKey, err)

Expand Down Expand Up @@ -200,7 +200,7 @@ func (p *Provider) buildACLConfigRoutersAndServices(t *topology.Topology, cfg *d

for _, ttKey := range svc.TrafficTargets {
if err := p.buildServicesAndRoutersForTrafficTarget(t, cfg, ttKey, scheme, trafficType, middlewareKeys); err != nil {
err = fmt.Errorf("unable to build routers and services: %v", err)
err = fmt.Errorf("unable to build routers and services: %w", err)
t.ServiceTrafficTargets[ttKey].AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficTarget %q: %v", ttKey, err)

Expand Down Expand Up @@ -235,7 +235,7 @@ func (p *Provider) buildServicesAndRoutersForHTTPService(t *topology.Topology, c
for portID, svcPort := range svc.Ports {
entrypoint, err := p.buildHTTPEntrypoint(portID)
if err != nil {
err = fmt.Errorf("unable to build HTTP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build HTTP entrypoint for port %d: %w", svcPort.Port, err)
svc.AddError(err)
p.logger.Errorf("Error building dynamic configuration for Service %q: %v", svcKey, err)

Expand All @@ -255,7 +255,7 @@ func (p *Provider) buildServicesAndRoutersForTCPService(t *topology.Topology, cf
for _, svcPort := range svc.Ports {
entrypoint, err := p.buildTCPEntrypoint(svc, svcPort.Port)
if err != nil {
err = fmt.Errorf("unable to build TCP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build TCP entrypoint for port %d: %w", svcPort.Port, err)
svc.AddError(err)
p.logger.Errorf("Error building dynamic configuration for Service %q: %v", svcKey, err)

Expand All @@ -273,7 +273,7 @@ func (p *Provider) buildServicesAndRoutersForUDPService(t *topology.Topology, cf
for _, svcPort := range svc.Ports {
entrypoint, err := p.buildUDPEntrypoint(svc, svcPort.Port)
if err != nil {
err = fmt.Errorf("unable to build UDP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build UDP entrypoint for port %d: %w", svcPort.Port, err)
svc.AddError(err)
p.logger.Errorf("Error building dynamic configuration for Service %q: %v", svcKey, err)

Expand Down Expand Up @@ -321,7 +321,7 @@ func (p *Provider) buildHTTPServicesAndRoutersForTrafficTarget(t *topology.Topol
for portID, svcPort := range tt.Destination.Ports {
entrypoint, err := p.buildHTTPEntrypoint(portID)
if err != nil {
err = fmt.Errorf("unable to build HTTP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build HTTP entrypoint for port %d: %w", svcPort.Port, err)
tt.AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficTarget %q: %v", ttKey, err)

Expand Down Expand Up @@ -362,7 +362,7 @@ func (p *Provider) buildTCPServicesAndRoutersForTrafficTarget(t *topology.Topolo
for _, svcPort := range tt.Destination.Ports {
entrypoint, err := p.buildTCPEntrypoint(ttSvc, svcPort.Port)
if err != nil {
err = fmt.Errorf("unable to build TCP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build TCP entrypoint for port %d: %w", svcPort.Port, err)
tt.AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficTarget %q: %v", ttKey, err)

Expand Down Expand Up @@ -420,7 +420,7 @@ func (p *Provider) buildHTTPServiceAndRoutersForTrafficSplit(t *topology.Topolog
for portID, svcPort := range tsSvc.Ports {
backendSvcs, err := p.buildServicesForTrafficSplitBackends(t, cfg, ts, svcPort, scheme)
if err != nil {
err = fmt.Errorf("unable to build HTTP backend services and port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build HTTP backend services and port %d: %w", svcPort.Port, err)
ts.AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficSplit %q: %v", tsKey, err)

Expand All @@ -429,7 +429,7 @@ func (p *Provider) buildHTTPServiceAndRoutersForTrafficSplit(t *topology.Topolog

entrypoint, err := p.buildHTTPEntrypoint(portID)
if err != nil {
err = fmt.Errorf("unable to build HTTP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build HTTP entrypoint for port %d: %w", svcPort.Port, err)
ts.AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficSplit %q: %v", tsKey, err)

Expand Down Expand Up @@ -464,7 +464,7 @@ func (p *Provider) buildTCPServiceAndRoutersForTrafficSplit(cfg *dynamic.Configu
for _, svcPort := range tsSvc.Ports {
entrypoint, err := p.buildTCPEntrypoint(tsSvc, svcPort.Port)
if err != nil {
err = fmt.Errorf("unable to build TCP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build TCP entrypoint for port %d: %w", svcPort.Port, err)
ts.AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficSplit %q: %v", tsKey, err)

Expand Down Expand Up @@ -495,7 +495,7 @@ func (p *Provider) buildUDPServiceAndRoutersForTrafficSplit(cfg *dynamic.Configu
for _, svcPort := range tsSvc.Ports {
entrypoint, err := p.buildUDPEntrypoint(tsSvc, svcPort.Port)
if err != nil {
err = fmt.Errorf("unable to build UDP entrypoint for port %d: %v", svcPort.Port, err)
err = fmt.Errorf("unable to build UDP entrypoint for port %d: %w", svcPort.Port, err)
ts.AddError(err)
p.logger.Errorf("Error building dynamic configuration for TrafficSplit %q: %v", tsKey, err)

Expand Down
Loading

0 comments on commit 828353e

Please sign in to comment.