Skip to content

Commit

Permalink
Merge branch 'main' into alpeb/no-ns-helm-core
Browse files Browse the repository at this point in the history
  • Loading branch information
alpeb committed Aug 17, 2021
2 parents 11ff9db + 6415e8c commit fff86d1
Show file tree
Hide file tree
Showing 17 changed files with 429 additions and 76 deletions.
130 changes: 130 additions & 0 deletions cli/cmd/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package cmd

import (
"context"
"testing"

"github.com/linkerd/linkerd2/pkg/k8s"
)

func TestGetPodsFor(t *testing.T) {

configs := []string{
// pod-1
`apiVersion: v1
kind: Pod
metadata:
name: pod-1
namespace: ns
uid: pod-1
labels:
app: foo
ownerReferences:
- apiVersion: apps/v1
controller: true
kind: ReplicaSet
name: rs-1
uid: rs-1
`,
// rs-1
`apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs-1
namespace: ns
uid: rs-1
labels:
app: foo
ownerReferences:
- apiVersion: apps/v1
controller: true
kind: Deployment
name: deploy-1
uid: deploy-1
spec:
selector:
matchLabels:
app: foo
`,
// deploy-1
`apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-1
namespace: ns
uid: deploy-1
spec:
selector:
matchLabels:
app: foo
`,
// pod-2
`apiVersion: v1
kind: Pod
metadata:
name: pod-2
namespace: ns
uid: pod-2
labels:
app: foo
ownerReferences:
- apiVersion: apps/v1
controller: true
kind: ReplicaSet
name: rs-2
uid: rs-2
`,
// rs-2
`apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs-2
namespace: ns
uid: rs-2
labels:
app: foo
ownerReferences:
- apiVersion: apps/v1
controller: true
kind: Deployment
name: deploy-2
uid: deploy-2
spec:
selector:
matchLabels:
app: foo
`,
// deploy-2
`apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-2
namespace: ns
uid: deploy-2
spec:
selector:
matchLabels:
app: foo
`}

k8sClient, err := k8s.NewFakeAPI(configs...)
if err != nil {
t.Fatalf("Unexpected error %s", err)
}

// Both pod-1 and pod-2 have labels which match deploy-1's selector.
// However, only pod-1 is owned by deploy-1 according to the owner references.
// Owner references should be considered authoritative to resolve ambiguity
// when deployments have overlapping seletors.
pods, err := getPodsFor(context.Background(), k8sClient, "ns", "deploy/deploy-1")
if err != nil {
t.Fatalf("Unexpected error %s", err)
}

if len(pods) != 1 {
for _, p := range pods {
t.Logf("%s/%s", p.Namespace, p.Name)
}
t.Fatalf("Expected 1 pod, got %d", len(pods))
}
}
2 changes: 1 addition & 1 deletion cli/cmd/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func repair(ctx context.Context, forced bool) error {
}

// Load the stored config
config, err := k8sAPI.CoreV1().ConfigMaps(controlPlaneNamespace).Get(ctx, "linkerd-config", metav1.GetOptions{})
config, err := k8sAPI.CoreV1().ConfigMaps(controlPlaneNamespace).Get(ctx, k8s.ConfigConfigMapName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Failed to load linkerd-config: %s", err)
}
Expand Down
1 change: 1 addition & 0 deletions multicluster/charts/linkerd-multicluster-link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Kubernetes: `>=1.16.0-0`
|-----|------|---------|-------------|
| controllerImage | string | `"cr.l5d.io/linkerd/controller"` | Docker image for the Service mirror component (uses the Linkerd controller image) |
| controllerImageVersion | string | `"linkerdVersionValue"` | Tag for the Service Mirror container Docker image |
| enableHeadlessServices | bool | `false` | Toggle support for mirroring headless services |
| gateway.probe.port | int | `4191` | The port used for liveliness probing |
| logLevel | string | `"info"` | Log level for the Multicluster components |
| serviceMirrorRetryLimit | int | `3` | Number of times update from the remote cluster is allowed to be requeued (retried) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ spec:
- -log-level={{.Values.logLevel}}
- -event-requeue-limit={{.Values.serviceMirrorRetryLimit}}
- -namespace={{.Release.Namespace}}
{{- if .Values.enableHeadlessServices }}
- -enable-headless-services
{{- end }}
- {{.Values.targetClusterName}}
image: {{.Values.controllerImage}}:{{.Values.controllerImageVersion}}
name: service-mirror
Expand Down
2 changes: 2 additions & 0 deletions multicluster/charts/linkerd-multicluster-link/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
controllerImage: cr.l5d.io/linkerd/controller
# -- Tag for the Service Mirror container Docker image
controllerImageVersion: linkerdVersionValue
# -- Toggle support for mirroring headless services
enableHeadlessServices: false
gateway:
probe:
# -- The port used for liveliness probing
Expand Down
7 changes: 2 additions & 5 deletions pkg/k8s/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ const (
// ConfigConfigMapName is the name of the ConfigMap containing the linkerd controller configuration.
ConfigConfigMapName = "linkerd-config"

// AddOnsConfigMapName is the name of the ConfigMap containing the linkerd add-ons configuration.
AddOnsConfigMapName = "linkerd-config-addons"
// DebugContainerName is the name of the default linkerd debug container
DebugContainerName = "linkerd-debug"

// DebugSidecarImage is the image name of the default linkerd debug container
DebugSidecarImage = "cr.l5d.io/linkerd/debug"
Expand Down Expand Up @@ -294,9 +294,6 @@ const (
// IdentityIssuerTrustAnchorsNameExternal is the issuer's certificate file (when using cert-manager).
IdentityIssuerTrustAnchorsNameExternal = "ca.crt"

// IdentityIssuerTrustAnchorsName is the trust anchors name.
IdentityIssuerTrustAnchorsName = "ca-bundle.crt"

// ProxyPortName is the name of the Linkerd Proxy's proxy port.
ProxyPortName = "linkerd-proxy"

Expand Down
12 changes: 11 additions & 1 deletion pkg/k8s/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ func newPortForward(
emitLogs bool,
) (*PortForward, error) {

req := k8sAPI.CoreV1().RESTClient().Post().
restClient := k8sAPI.CoreV1().RESTClient()
// This early return is for testing purposes. If the k8sAPI is a fake
// client, attempting to create a request will result in a nil-pointer
// panic. Instead, we return with no port-forward and no error.
if fakeRest, ok := restClient.(*rest.RESTClient); ok {
if fakeRest == nil {
return nil, nil
}
}

req := restClient.Post().
Resource("pods").
Namespace(namespace).
Name(podName).
Expand Down
Loading

0 comments on commit fff86d1

Please sign in to comment.