Skip to content

Commit a90bcc0

Browse files
authored
Merge pull request #1121 from devigned/cp-logs
output kube-system logs from workload clusters
2 parents 51851ec + ae02111 commit a90bcc0

22 files changed

+108
-8
lines changed

templates/test/cluster-template-prow-ci-version.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
cloud-config: /etc/kubernetes/azure.json
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
66+
v: "4"
6667
extraVolumes:
6768
- hostPath: /etc/kubernetes/azure.json
6869
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-ipv6.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ spec:
8484
cluster-cidr: 2001:1234:5678:9a40::/58
8585
cluster-name: ${CLUSTER_NAME}
8686
configure-cloud-routes: "true"
87+
v: "4"
8788
extraVolumes:
8889
- hostPath: /etc/kubernetes/azure.json
8990
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-machine-pool-ci-version.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
cloud-config: /etc/kubernetes/azure.json
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
66+
v: "4"
6667
extraVolumes:
6768
- hostPath: /etc/kubernetes/azure.json
6869
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-machine-pool-windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ spec:
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
6666
configure-cloud-routes: "false"
67+
v: "4"
6768
extraVolumes:
6869
- hostPath: /etc/kubernetes/azure.json
6970
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-machine-pool.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
cloud-config: /etc/kubernetes/azure.json
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
66+
v: "4"
6667
extraVolumes:
6768
- hostPath: /etc/kubernetes/azure.json
6869
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-multi-tenancy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ spec:
6868
cloud-config: /etc/kubernetes/azure.json
6969
cloud-provider: azure
7070
cluster-name: ${CLUSTER_NAME}
71+
v: "4"
7172
extraVolumes:
7273
- hostPath: /etc/kubernetes/azure.json
7374
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-nvidia-gpu.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
cloud-config: /etc/kubernetes/azure.json
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
66+
v: "4"
6667
extraVolumes:
6768
- hostPath: /etc/kubernetes/azure.json
6869
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-private.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ spec:
7878
cloud-config: /etc/kubernetes/azure.json
7979
cloud-provider: azure
8080
cluster-name: ${CLUSTER_NAME}
81+
v: "4"
8182
extraVolumes:
8283
- hostPath: /etc/kubernetes/azure.json
8384
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow-windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ spec:
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
6666
configure-cloud-routes: "false"
67+
v: "4"
6768
extraVolumes:
6869
- hostPath: /etc/kubernetes/azure.json
6970
mountPath: /etc/kubernetes/azure.json

templates/test/cluster-template-prow.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
cloud-config: /etc/kubernetes/azure.json
6464
cloud-provider: azure
6565
cluster-name: ${CLUSTER_NAME}
66+
v: "4"
6667
extraVolumes:
6768
- hostPath: /etc/kubernetes/azure.json
6869
mountPath: /etc/kubernetes/azure.json
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kind: KubeadmControlPlane
2+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
3+
metadata:
4+
name: "${CLUSTER_NAME}-control-plane"
5+
spec:
6+
kubeadmConfigSpec:
7+
clusterConfiguration:
8+
controllerManager:
9+
extraArgs:
10+
v: "4"

templates/test/prow-ipv6/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ resources:
66
- cni-resource-set.yaml
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
9+
- ../patches/controller-manager.yaml
910
- patches/cluster-cni.yaml
1011

templates/test/prow-machine-pool-ci-version/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ resources:
55
- ../prow-machine-pool
66
patchesStrategicMerge:
77
- ../patches/control-plane-image-ci-version.yaml
8+
- ../patches/controller-manager.yaml
89
- patches/machine-pool-ci-version.yaml

templates/test/prow-machine-pool-windows/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ resources:
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
99
- ../patches/cni-resource-set.yaml
10+
- ../patches/controller-manager.yaml
1011

templates/test/prow-machine-pool/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ resources:
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
99
- ../patches/cni-resource-set.yaml
10+
- ../patches/controller-manager.yaml

templates/test/prow-multi-tenancy/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ resources:
66
- cni-resource-set.yaml
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
9+
- ../patches/controller-manager.yaml
910
- patches/cluster-cni.yaml

templates/test/prow-nvidia-gpu/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ resources:
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
99
- ../patches/cni-resource-set.yaml
10+
- ../patches/controller-manager.yaml
1011
patchesJson6902:
1112
- path: patches/node-storage-type.yaml
1213
target:

templates/test/prow-private/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ resources:
66
- cni-resource-set.yaml
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
9+
- ../patches/controller-manager.yaml
910
- patches/cluster-cni.yaml
1011
- patches/custom-vnet.yaml
1112

templates/test/prow-windows/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ resources:
77
patchesStrategicMerge:
88
- ../patches/tags.yaml
99
- ../patches/cni-resource-set.yaml
10+
- ../patches/controller-manager.yaml

templates/test/prow/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ patchesStrategicMerge:
99
- ../patches/tags.yaml
1010
- ../patches/mhc.yaml
1111
- ../patches/cni-resource-set.yaml
12+
- ../patches/controller-manager.yaml

test/e2e/azure_lb.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import (
2727
. "github.com/onsi/gomega"
2828
k8snet "k8s.io/utils/net"
2929

30-
deploymentBuilder "sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/deployment"
31-
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/job"
32-
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/node"
33-
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/windows"
34-
3530
corev1 "k8s.io/api/core/v1"
3631
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3732
"k8s.io/client-go/kubernetes"
3833
"sigs.k8s.io/cluster-api/test/framework"
34+
35+
deploymentBuilder "sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/deployment"
36+
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/job"
37+
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/node"
38+
"sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/windows"
3939
)
4040

4141
// AzureLBSpecInput is the input for AzureLBSpec.

test/e2e/e2e_suite_test.go

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ limitations under the License.
1919
package e2e
2020

2121
import (
22+
"bufio"
2223
"context"
2324
"flag"
2425
"fmt"
26+
"io"
2527
"os"
28+
"path"
2629
"path/filepath"
2730
"strings"
2831
"testing"
@@ -32,14 +35,17 @@ import (
3235
"github.com/onsi/ginkgo/config"
3336
"github.com/onsi/ginkgo/reporters"
3437
. "github.com/onsi/gomega"
38+
corev1 "k8s.io/api/core/v1"
3539
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3640
"k8s.io/apimachinery/pkg/runtime"
3741
"k8s.io/apimachinery/pkg/runtime/schema"
38-
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
3942
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"
4043
"sigs.k8s.io/cluster-api/test/framework"
4144
"sigs.k8s.io/cluster-api/test/framework/bootstrap"
4245
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
46+
"sigs.k8s.io/controller-runtime/pkg/client"
47+
48+
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
4349
)
4450

4551
// Test suite flags
@@ -80,6 +86,71 @@ var (
8086
useCIArtifacts bool
8187
)
8288

89+
type (
90+
AzureClusterProxy struct {
91+
framework.ClusterProxy
92+
}
93+
)
94+
95+
func NewAzureClusterProxy(name string, kubeconfigPath string, scheme *runtime.Scheme, options ...framework.Option) *AzureClusterProxy {
96+
return &AzureClusterProxy{
97+
ClusterProxy: framework.NewClusterProxy(name, kubeconfigPath, scheme, options...),
98+
}
99+
}
100+
101+
func (acp *AzureClusterProxy) CollectWorkloadClusterLogs(ctx context.Context, namespace, name, outputPath string) {
102+
const (
103+
kubesystem = "kube-system"
104+
)
105+
106+
Byf("Dumping workload cluster %s/%s logs", namespace, name)
107+
acp.ClusterProxy.CollectWorkloadClusterLogs(ctx, namespace, name, outputPath)
108+
109+
Byf("Dumping workload cluster %s/%s kube-system pod logs", namespace, name)
110+
aboveMachinesPath := strings.Replace(outputPath, "/machines", "", 1)
111+
workload := acp.GetWorkloadCluster(ctx, namespace, name)
112+
pods := &corev1.PodList{}
113+
Expect(workload.GetClient().List(ctx, pods, client.InNamespace(kubesystem))).To(Succeed())
114+
115+
for _, pod := range pods.Items {
116+
for _, container := range pod.Spec.Containers {
117+
// Watch each container's logs in a goroutine so we can stream them all concurrently.
118+
go func(pod corev1.Pod, container corev1.Container) {
119+
defer GinkgoRecover()
120+
121+
Byf("Creating log watcher for controller %s/%s, container %s", kubesystem, pod.Name, container.Name)
122+
logFile := path.Join(aboveMachinesPath, kubesystem, pod.Name, container.Name+".log")
123+
Expect(os.MkdirAll(filepath.Dir(logFile), 0755)).To(Succeed())
124+
125+
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
126+
Expect(err).NotTo(HaveOccurred())
127+
defer f.Close()
128+
129+
opts := &corev1.PodLogOptions{
130+
Container: container.Name,
131+
Follow: true,
132+
}
133+
134+
podLogs, err := workload.GetClientSet().CoreV1().Pods(kubesystem).GetLogs(pod.Name, opts).Stream()
135+
if err != nil {
136+
// Failing to stream logs should not cause the test to fail
137+
Byf("Error starting logs stream for pod %s/%s, container %s: %v", kubesystem, pod.Name, container.Name, err)
138+
return
139+
}
140+
defer podLogs.Close()
141+
142+
out := bufio.NewWriter(f)
143+
defer out.Flush()
144+
_, err = out.ReadFrom(podLogs)
145+
if err != nil && err != io.ErrUnexpectedEOF {
146+
// Failing to stream logs should not cause the test to fail
147+
Byf("Got error while streaming logs for pod %s/%s, container %s: %v", kubesystem, pod.Name, container.Name, err)
148+
}
149+
}(pod, container)
150+
}
151+
}
152+
}
153+
83154
func init() {
84155
flag.StringVar(&configPath, "e2e.config", "", "path to the e2e config file")
85156
flag.StringVar(&artifactFolder, "e2e.artifacts-folder", "", "folder where e2e test artifact should be stored")
@@ -140,7 +211,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
140211
kubeconfigPath := parts[3]
141212

142213
e2eConfig = loadE2EConfig(configPath)
143-
bootstrapClusterProxy = framework.NewClusterProxy("bootstrap", kubeconfigPath, initScheme(),
214+
bootstrapClusterProxy = NewAzureClusterProxy("bootstrap", kubeconfigPath, initScheme(),
144215
framework.WithMachineLogCollector(AzureLogCollector{}))
145216
})
146217

@@ -231,7 +302,7 @@ func setupBootstrapCluster(config *clusterctl.E2EConfig, scheme *runtime.Scheme,
231302
Expect(kubeconfigPath).To(BeAnExistingFile(), "Failed to get the kubeconfig file for the bootstrap cluster")
232303
}
233304

234-
clusterProxy := framework.NewClusterProxy("bootstrap", kubeconfigPath, scheme)
305+
clusterProxy := NewAzureClusterProxy("bootstrap", kubeconfigPath, scheme)
235306
Expect(clusterProxy).ToNot(BeNil(), "Failed to get a bootstrap cluster proxy")
236307

237308
return clusterProvider, clusterProxy

0 commit comments

Comments
 (0)