Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 18f42d0

Browse files
committed
Clean up kind collect logs code
Signed-off-by: JoshVanL <[email protected]>
1 parent 18fa393 commit 18f42d0

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

test/kind/kind.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,13 @@ func DeleteCluster(name string) error {
130130
}
131131

132132
func (k *Kind) Destroy() error {
133-
log.Infof("kind: destroying cluster %q", clusterName)
134-
135-
provider := cluster.NewProvider()
136-
logDir := filepath.Join(k.rootPath, "artifacts", "logs")
137-
138-
if err := os.RemoveAll(logDir); err != nil {
139-
log.Errorf("kind: failed to remove old logs directory: %s", err)
140-
} else {
141-
if err := os.MkdirAll(logDir, 0755); err != nil {
142-
log.Errorf("kind: failed to create logs directory: %s", err)
143-
} else {
144-
if err := provider.CollectLogs(clusterName, logDir); err != nil {
145-
log.Errorf("kind: failed to collect logs: %s", err)
146-
} else {
147-
log.Infof("kind: collected logs at %q", logDir)
148-
}
149-
}
133+
if err := k.collectLogs(); err != nil {
134+
// Don't hard fail here as we should still attempt to delete the cluster
135+
log.Errorf("kind: failed to collect logs: %s", err)
150136
}
151137

152138
log.Infof("kind: destroying cluster %q", clusterName)
139+
153140
if err := DeleteCluster(clusterName); err != nil {
154141
return fmt.Errorf("failed to delete kind cluster: %s", err)
155142
}
@@ -163,6 +150,29 @@ func (k *Kind) Destroy() error {
163150
return nil
164151
}
165152

153+
func (k *Kind) collectLogs() error {
154+
provider := cluster.NewProvider()
155+
logDir := filepath.Join(k.rootPath, "artifacts", "logs")
156+
157+
log.Infof("kind: collecting logs to %q", logDir)
158+
159+
if err := os.RemoveAll(logDir); err != nil {
160+
return fmt.Errorf("failed to remove old logs directory: %s", err)
161+
}
162+
163+
if err := os.MkdirAll(logDir, 0755); err != nil {
164+
return fmt.Errorf("failed to create logs directory: %s", err)
165+
}
166+
167+
if err := provider.CollectLogs(clusterName, logDir); err != nil {
168+
return fmt.Errorf("failed to collect logs: %s", err)
169+
}
170+
171+
log.Infof("kind: collected logs at %q", logDir)
172+
173+
return nil
174+
}
175+
166176
func (k *Kind) KubeClient() *kubernetes.Clientset {
167177
return k.client
168178
}

test/util/tls.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const (
2626
prefix = "kube-oidc-proxy"
2727
)
2828

29-
//TODO: move me to test/util
30-
3129
func NewTLSSelfSignedCertKey(host string, netIPs []net.IP, dnsNames []string) (*KeyBundle, error) {
3230
certBytes, keyBytes, err := cert.GenerateSelfSignedCertKey(host, netIPs, dnsNames)
3331
if err != nil {

0 commit comments

Comments
 (0)