Skip to content

Commit

Permalink
Removed usage of files
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Tincelin committed Jun 11, 2021
1 parent 147b24b commit 8d1cf19
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 1,671 deletions.
100 changes: 34 additions & 66 deletions cmd/aks-periscope/aks-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ import (
)

func main() {
zipAndExportMode := true
exporter := &exporter.AzureBlobExporter{}
creationTimeStamp, err := utils.GetCreationTimeStamp()
if err != nil {
log.Fatalf("Failed to get creation timestamp: %v", err)
}

err := utils.CreateCRD()
hostname, err := utils.GetHostName()
if err != nil {
log.Fatalf("Failed to get the hostname on which AKS Periscope is running: %v", err)
}

if err := utils.CreateCRD(); err != nil {
log.Fatalf("Failed to create CRD: %v", err)
}

exporter := exporter.NewAzureBlobExporter(creationTimeStamp, hostname)

clusterType := os.Getenv("CLUSTER_TYPE")

// Copies self-signed cert information to container if application is running on Azure Stack Cloud.
Expand All @@ -32,30 +40,27 @@ func main() {
}
}

collectors := []interfaces.Collector{}
containerLogsCollector := collector.NewContainerLogsCollector(exporter)
networkOutboundCollector := collector.NewNetworkOutboundCollector(5, exporter)
dnsCollector := collector.NewDNSCollector(exporter)
kubeObjectsCollector := collector.NewKubeObjectsCollector(exporter)
systemLogsCollector := collector.NewSystemLogsCollector(exporter)
ipTablesCollector := collector.NewIPTablesCollector(exporter)
nodeLogsCollector := collector.NewNodeLogsCollector(exporter)
kubeletCmdCollector := collector.NewKubeletCmdCollector(exporter)
systemPerfCollector := collector.NewSystemPerfCollector(exporter)
helmCollector := collector.NewHelmCollector(exporter)
containerLogsCollector := collector.NewContainerLogsCollector()
networkOutboundCollector := collector.NewNetworkOutboundCollector()
dnsCollector := collector.NewDNSCollector()
kubeObjectsCollector := collector.NewKubeObjectsCollector()
systemLogsCollector := collector.NewSystemLogsCollector()
ipTablesCollector := collector.NewIPTablesCollector()
nodeLogsCollector := collector.NewNodeLogsCollector()
kubeletCmdCollector := collector.NewKubeletCmdCollector()
systemPerfCollector := collector.NewSystemPerfCollector()
helmCollector := collector.NewHelmCollector()

collectors := []interfaces.Collector{
containerLogsCollector,
dnsCollector,
kubeObjectsCollector,
networkOutboundCollector,
}

if strings.EqualFold(clusterType, "connectedCluster") {
collectors = append(collectors, containerLogsCollector)
collectors = append(collectors, dnsCollector)
collectors = append(collectors, helmCollector)
collectors = append(collectors, kubeObjectsCollector)
collectors = append(collectors, networkOutboundCollector)

} else {
collectors = append(collectors, containerLogsCollector)
collectors = append(collectors, dnsCollector)
collectors = append(collectors, kubeObjectsCollector)
collectors = append(collectors, networkOutboundCollector)
collectors = append(collectors, systemLogsCollector)
collectors = append(collectors, ipTablesCollector)
collectors = append(collectors, nodeLogsCollector)
Expand All @@ -78,18 +83,18 @@ func main() {
}

log.Printf("Collector: %s, export data", c.GetName())
err = c.Export()
if err != nil {
if err = exporter.Export(c); err != nil {
log.Printf("Collector: %s, export data failed: %v", c.GetName(), err)
}
}(c)
}

collectorGrp.Wait()

diagnosers := []interfaces.Diagnoser{}
diagnosers = append(diagnosers, diagnoser.NewNetworkConfigDiagnoser(dnsCollector, kubeletCmdCollector, exporter))
diagnosers = append(diagnosers, diagnoser.NewNetworkOutboundDiagnoser(networkOutboundCollector, exporter))
diagnosers := []interfaces.Diagnoser{
diagnoser.NewNetworkConfigDiagnoser(dnsCollector, kubeletCmdCollector),
diagnoser.NewNetworkOutboundDiagnoser(networkOutboundCollector),
}

diagnoserGrp := new(sync.WaitGroup)

Expand All @@ -106,55 +111,18 @@ func main() {
}

log.Printf("Diagnoser: %s, export data", d.GetName())
err = d.Export()
if err != nil {
if err = exporter.Export(d); err != nil {
log.Printf("Diagnoser: %s, export data failed: %v", d.GetName(), err)
}
}(d)
}

diagnoserGrp.Wait()

if zipAndExportMode {
log.Print("Zip and export result files")
err := zipAndExport(exporter)
if err != nil {
log.Fatalf("Failed to zip and export result files: %v", err)
}
}
}

// zipAndExport zip the results and export
func zipAndExport(exporter interfaces.Exporter) error {
hostName, err := utils.GetHostName()
if err != nil {
return err
}

creationTimeStamp, err := utils.GetCreationTimeStamp()
if err != nil {
return err
}

sourcePathOnHost := "/var/log/aks-periscope/" + strings.Replace(creationTimeStamp, ":", "-", -1) + "/" + hostName
zipFileOnHost := sourcePathOnHost + "/" + hostName + ".zip"
zipFileOnContainer := strings.TrimPrefix(zipFileOnHost, "/var/log")

_, err = utils.RunCommandOnHost("zip", "-r", zipFileOnHost, sourcePathOnHost)
if err != nil {
return err
}

err = exporter.Export([]string{zipFileOnContainer})
if err != nil {
return err
}

// TODO: Hack: for now AKS-Periscope is running as a deamonset so it shall not stop (or the pod will be restarted)
// Revert from https://github.com/Azure/aks-periscope/blob/b98d66a238e942158ef2628a9315b58937ff9c8f/cmd/aks-periscope/aks-periscope.go#L70
select {}

// TODO: remove this //nolint comment once the select{} has been removed
//nolint:govet
return nil
}
8 changes: 0 additions & 8 deletions deployment/aks-periscope.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,13 @@ spec:
name: clustertype-config
- secretRef:
name: azureblob-secret
volumeMounts:
- mountPath: /aks-periscope
name: aks-periscope-storage
resources:
requests:
memory: "500Mi"
cpu: "250m"
limits:
memory: "2000Mi"
cpu: "1000m"
volumes:
- name: aks-periscope-storage
hostPath:
path: /var/log/aks-periscope
type: DirectoryOrCreate
---
apiVersion: v1
kind: Secret
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.15

require (
github.com/Azure/azure-storage-blob-go v0.7.0
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/golangci/golangci-lint v1.40.1 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.14 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/onsi/gomega v1.13.0
github.com/pkg/errors v0.9.1 // indirect
)
Loading

0 comments on commit 8d1cf19

Please sign in to comment.