Skip to content

Commit

Permalink
Update docker_logcollector.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecile Robert-Michon committed May 6, 2021
1 parent 4dfa272 commit 91a58bc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions test/framework/docker_logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,25 @@ import (
// DockerLogCollector collect logs from a CAPD workload cluster.
type DockerLogCollector struct{}

// generateContainerName return a container name using the same rule used in CAPD.
// machineContainerName return a container name using the same rule used in CAPD.
// NOTE: if the cluster name is already included in the machine name, the cluster name is not add thus
// avoiding \"sethostname: invalid argument\" errors due to container name too long.
func generateContainerName(cluster, machine string) string {
func machineContainerName(cluster, machine string) string {
if strings.HasPrefix(machine, cluster) {
return machine
}
return fmt.Sprintf("%s-%s", cluster, machine)
}

func (k DockerLogCollector) CollectMachineLog(ctx context.Context, managementClusterClient client.Client, m *clusterv1.Machine, outputPath string) error {
containerName := generateContainerName(m.Spec.ClusterName, m.Name)
containerName := machineContainerName(m.Spec.ClusterName, m.Name)
return k.collectLogsFromNode(outputPath, containerName)
}


func (k DockerLogCollector) CollectMachinePoolLog(ctx context.Context, managementClusterClient client.Client, m *expv1.MachinePool, outputPath string) error {
for _, instance := range m.Status.NodeRefs {
containerName := generateContainerName(m.Spec.ClusterName, instance.Name)
err := k.collectLogsFromNode(filepath.Join(outputPath, instance.Name), containerName)
err := k.collectLogsFromNode(filepath.Join(outputPath, instance.Name), instance.Name)
if err != nil {
return err
}
Expand Down

0 comments on commit 91a58bc

Please sign in to comment.