Skip to content

Commit 2854366

Browse files
author
Sophie Zhao
committed
# This is a combination of 127 commits.
# This is the 1st commit message: Revert "introduce arcmode" This reverts commit 5f4fed4. # This is the commit message #2: remove secrets # This is the commit message Azure#3: add print statement # This is the commit message Azure#4: update print statement # This is the commit message Azure#5: committed # This is the commit message Azure#6: committed # This is the commit message Azure#7: committed # This is the commit message Azure#8: committed # This is the commit message Azure#9: remove print statements # This is the commit message Azure#10: add helm collector # This is the commit message Azure#11: change helm command # This is the commit message Azure#12: add helm 3 installation # This is the commit message Azure#13: add curl command installation # This is the commit message Azure#14: change helm command # This is the commit message Azure#15: remove helm history # This is the commit message Azure#16: debug helm history # This is the commit message Azure#17: add repo command # This is the commit message Azure#18: change stable repo name # This is the commit message Azure#19: add write to file # This is the commit message Azure#20: add kured # This is the commit message Azure#21: change # This is the commit message Azure#22: changes # This is the commit message Azure#23: add default namespace # This is the commit message Azure#24: change # This is the commit message Azure#25: add integration test # This is the commit message Azure#26: changes # This is the commit message Azure#27: add helm test # This is the commit message Azure#28: change print statement to error # This is the commit message Azure#29: change # This is the commit message Azure#30: more changes # This is the commit message Azure#31: add go installation # This is the commit message Azure#32: fix unit test # This is the commit message Azure#33: iptables to Helm # This is the commit message Azure#34: add custom resource collector # This is the commit message Azure#35: add new exporter, diagnoser, collector # This is the commit message Azure#36: comment unused variables # This is the commit message Azure#37: debug exporter # This is the commit message Azure#38: filenames # This is the commit message Azure#39: test zip function # This is the commit message Azure#40: list files # This is the commit message Azure#41: fmt to log # This is the commit message Azure#42: delete lines # This is the commit message Azure#43: changed # This is the commit message Azure#44: get current directory # This is the commit message Azure#45: remove some print statements # This is the commit message Azure#46: test zip # This is the commit message Azure#47: changes # This is the commit message Azure#48: add windir check # This is the commit message Azure#49: minor fix # This is the commit message Azure#50: get hostname # This is the commit message Azure#51: add expose in dockerfile # This is the commit message Azure#52: add exec collector # This is the commit message Azure#53: mitigate exit code 126 # This is the commit message Azure#54: change curl url from example.com to dp endpoint # This is the commit message Azure#55: changes # This is the commit message Azure#56: uncomment exec # This is the commit message Azure#57: add new diagnoser # This is the commit message Azure#58: debugging # This is the commit message Azure#59: debug # This is the commit message Azure#60: debugging # This is the commit message Azure#61: remove print statements # This is the commit message Azure#62: remove print # This is the commit message Azure#63: add back crd print statement # This is the commit message Azure#64: change # This is the commit message Azure#65: change # This is the commit message Azure#66: update dataPoint name # This is the commit message Azure#67: modify forloop # This is the commit message Azure#68: add filename to datapoint # This is the commit message Azure#69: add back log prints # This is the commit message Azure#70: test # This is the commit message Azure#71: add fields to diagnostic signal # This is the commit message Azure#72: add config content to diagnoser # This is the commit message Azure#73: change format from yaml to json # This is the commit message Azure#74: add parameters for kubeobject config map # This is the commit message Azure#75: Revert "introduce arcmode" This reverts commit 5f4fed4. # This is the commit message Azure#76: fix helm collector style # This is the commit message Azure#77: revert changes that test arc customizations # This is the commit message Azure#78: fix merge conflicts # This is the commit message Azure#79: fix merge conflicts # This is the commit message Azure#80: Revert "Add v0.3 acr image for Private cluster fix. (Azure#22)" This reverts commit 49dd302. # This is the commit message Azure#81: fix merge conflicts # This is the commit message Azure#82: fix merge conflicts # This is the commit message Azure#83: add print statement # This is the commit message Azure#84: update print statement # This is the commit message Azure#85: committed # This is the commit message Azure#86: committed # This is the commit message Azure#87: committed # This is the commit message Azure#88: committed # This is the commit message Azure#89: remove print statements # This is the commit message Azure#90: fix merge conflicts # This is the commit message Azure#91: fix merge conflicts # This is the commit message Azure#92: fix merge conflicts # This is the commit message Azure#93: add repo command # This is the commit message Azure#94: change stable repo name # This is the commit message Azure#95: add write to file # This is the commit message Azure#96: add kured # This is the commit message Azure#97: change # This is the commit message Azure#98: changes # This is the commit message Azure#99: add default namespace # This is the commit message Azure#100: change # This is the commit message Azure#101: add integration test # This is the commit message Azure#102: changes # This is the commit message Azure#103: add helm test # This is the commit message Azure#104: change print statement to error # This is the commit message Azure#105: change # This is the commit message Azure#106: more changes # This is the commit message Azure#107: add go installation # This is the commit message Azure#108: fix unit test # This is the commit message Azure#109: add custom resource collector # This is the commit message Azure#110: fix merge conflicts # This is the commit message Azure#111: comment unused variables # This is the commit message Azure#112: debug exporter # This is the commit message Azure#113: filenames # This is the commit message Azure#114: test zip function # This is the commit message Azure#115: list files # This is the commit message Azure#116: fmt to log # This is the commit message Azure#117: delete lines # This is the commit message Azure#118: changed # This is the commit message Azure#119: get current directory # This is the commit message Azure#120: remove some print statements # This is the commit message Azure#121: test zip # This is the commit message Azure#122: changes # This is the commit message Azure#123: add windir check # This is the commit message Azure#124: minor fix # This is the commit message Azure#125: get hostname # This is the commit message Azure#126: add expose in dockerfile # This is the commit message Azure#127: add exec collector
1 parent 9499421 commit 2854366

File tree

14 files changed

+381
-25
lines changed

14 files changed

+381
-25
lines changed

builder/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor github.com/Azure/aks-periscope
66

77
FROM alpine
88
RUN apk --no-cache add ca-certificates
9+
RUN apk add curl openssl bash --no-cache
910
ADD https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl /usr/local/bin/kubectl
1011
RUN chmod +x /usr/local/bin/kubectl
12+
RUN curl -fsSl -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
13+
RUN chmod +x get_helm.sh
14+
RUN ./get_helm.sh
15+
1116
RUN mkdir /app
1217
WORKDIR /app
1318
COPY --from=builder /app/aks-periscope .
19+
EXPOSE 8080
1420
CMD ["./aks-periscope"]

cmd/aks-periscope/aks-periscope.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
func main() {
1717
zipAndExportMode := true
18+
//exporter := &exporter.LocalMachineExporter{}
1819
exporter := &exporter.AzureBlobExporter{}
1920
var waitgroup sync.WaitGroup
2021

@@ -23,8 +24,10 @@ func main() {
2324
log.Printf("Failed to create CRD: %+v", err)
2425
}
2526

26-
clusterType := strings.ToLower(os.Getenv("CLUSTER_TYPE"))
27+
clusterType := os.Getenv("CLUSTER_TYPE")
2728

29+
storageAccount := os.Getenv("AZURE_BLOB_ACCOUNT_NAME")
30+
log.Printf("Storage Account: %s", storageAccount)
2831
collectors := []interfaces.Collector{}
2932
containerLogsCollector := collector.NewContainerLogsCollector(exporter)
3033
collectors = append(collectors, containerLogsCollector)
@@ -41,7 +44,15 @@ func main() {
4144
kubeletCmdCollector := collector.NewKubeletCmdCollector(exporter)
4245
systemPerfCollector := collector.NewSystemPerfCollector(exporter)
4346

44-
if clusterType != "connectedcluster" {
47+
execCollector := collector.NewExecCollector(exporter)
48+
helmCollector := collector.NewHelmCollector(exporter)
49+
customResourceCollector := collector.NewCustomResourceCollector(exporter)
50+
51+
if clusterType == "connectedcluster" {
52+
collectors = append(collectors, helmCollector)
53+
collectors = append(collectors, execCollector)
54+
collectors = append(collectors, customResourceCollector)
55+
} else {
4556
collectors = append(collectors, systemLogsCollector)
4657
collectors = append(collectors, ipTablesCollector)
4758
collectors = append(collectors, nodeLogsCollector)
@@ -63,6 +74,7 @@ func main() {
6374
if err != nil {
6475
log.Printf("Collector: %s, export data failed: %+v\n", c.GetName(), err)
6576
}
77+
6678
waitgroup.Done()
6779
}(c)
6880
}

deployment/aks-periscope.yaml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apiVersion: v1
22
kind: Namespace
33
metadata:
4-
name: azure-k8-periscope
4+
name: aks-periscope
55
---
66
apiVersion: v1
77
kind: ServiceAccount
88
metadata:
99
name: aks-periscope-service-account
10-
namespace: azure-k8-periscope
10+
namespace: aks-periscope
1111
---
1212
apiVersion: rbac.authorization.k8s.io/v1
1313
kind: ClusterRole
@@ -28,7 +28,7 @@ metadata:
2828
subjects:
2929
- kind: ServiceAccount
3030
name: aks-periscope-service-account
31-
namespace: azure-k8-periscope
31+
namespace: aks-periscope
3232
roleRef:
3333
kind: ClusterRole
3434
name: aks-periscope-role
@@ -41,7 +41,7 @@ metadata:
4141
subjects:
4242
- kind: ServiceAccount
4343
name: aks-periscope-service-account
44-
namespace: azure-k8-periscope
44+
namespace: aks-periscope
4545
roleRef:
4646
kind: ClusterRole
4747
name: view
@@ -50,18 +50,18 @@ roleRef:
5050
apiVersion: apps/v1
5151
kind: DaemonSet
5252
metadata:
53-
name: azure-k8-periscope
54-
namespace: azure-k8-periscope
53+
name: aks-periscope
54+
namespace: aks-periscope
5555
labels:
56-
app: azure-k8-periscope
56+
app: aks-periscope
5757
spec:
5858
selector:
5959
matchLabels:
60-
app: azure-k8-periscope
60+
app: aks-periscope
6161
template:
6262
metadata:
6363
labels:
64-
app: azure-k8-periscope
64+
app: aks-periscope
6565
spec:
6666
serviceAccountName: aks-periscope-service-account
6767
hostPID: true
@@ -80,6 +80,8 @@ spec:
8080
name: kubeobjects-config
8181
- configMapRef:
8282
name: nodelogs-config
83+
- configMapRef:
84+
name: clustertype-config
8385
- secretRef:
8486
name: azureblob-secret
8587
volumeMounts:
@@ -102,43 +104,43 @@ apiVersion: v1
102104
kind: Secret
103105
metadata:
104106
name: azureblob-secret
105-
namespace: azure-k8-periscope
107+
namespace: aks-periscope
106108
type: Opaque
107109
data:
108-
AZURE_BLOB_ACCOUNT_NAME: Y2Nzb3BoaWV6aGFvYXJuc2FlYXN0dXMy
109-
AZURE_BLOB_SAS_KEY: P3N2PTIwMjAtMDItMTAmc3M9YmZxdCZzcnQ9c2NvJnNwPXJ3ZGxhY3VweCZzZT0yMDIxLTA0LTIwVDAwOjA5OjM0WiZzdD0yMDIxLTA0LTE5VDE2OjA5OjM0WiZzcHI9aHR0cHMmc2lnPXZrM05FZ2ZBQm93a0RoQXJ5Rkd6b0NHJTJGRDB5SGUlMkJNYkg1SG82SmR1dmFrJTNE
110+
AZURE_BLOB_ACCOUNT_NAME: # <accountName, base64 encoded>
111+
AZURE_BLOB_SAS_KEY: # <saskey, base64 encoded>
110112
---
111113
apiVersion: v1
112114
kind: ConfigMap
113115
metadata:
114116
name: containerlogs-config
115-
namespace: azure-k8-periscope
117+
namespace: aks-periscope
116118
data:
117119
DIAGNOSTIC_CONTAINERLOGS_LIST: azure-arc
118120
---
119121
apiVersion: v1
120122
kind: ConfigMap
121123
metadata:
122124
name: kubeobjects-config
123-
namespace: azure-k8-periscope
125+
namespace: aks-periscope
124126
data:
125127
DIAGNOSTIC_KUBEOBJECTS_LIST: azure-arc/pod azure-arc/service azure-arc/deployment
126128
---
127129
apiVersion: v1
128130
kind: ConfigMap
129131
metadata:
130132
name: nodelogs-config
131-
namespace: azure-k8-periscope
133+
namespace: aks-periscope
132134
data:
133135
DIAGNOSTIC_NODELOGS_LIST: /var/log/azure/cluster-provision.log /var/log/cloud-init.log
134136
---
135137
apiVersion: v1
136138
kind: ConfigMap
137139
metadata:
138140
name: clustertype-config
139-
namespace: azure-k8-periscope
141+
namespace: aks-periscope
140142
data:
141-
CLUSTER_TYPE: # <cluster type, options: ConnectedCluster, ManagedCluster, ArcAppliances, etc.>
143+
CLUSTER_TYPE: connectedcluster
142144
---
143145
apiVersion: apiextensions.k8s.io/v1beta1
144146
kind: CustomResourceDefinition
@@ -167,4 +169,4 @@ spec:
167169
singular: diagnostic
168170
kind: Diagnostic
169171
shortNames:
170-
- apd
172+
- apd

integration/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM golang AS builder
2+
RUN mkdir /app
3+
ADD . /app
4+
WORKDIR /app
5+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor github.com/Azure/aks-periscope/cmd/aks-periscope
6+
7+
FROM alpine
8+
RUN apk --no-cache add ca-certificates
9+
RUN apk add curl openssl bash --no-cache
10+
ADD https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl /usr/local/bin/kubectl
11+
RUN chmod +x /usr/local/bin/kubectl
12+
RUN curl -fsSl -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
13+
RUN chmod +x get_helm.sh
14+
RUN ./get_helm.sh
15+
16+
RUN apk add --no-cache git make musl-dev go
17+
18+
# Configure Go
19+
ENV GOROOT /usr/lib/go
20+
ENV GOPATH /go
21+
ENV PATH /go/bin:$PATH
22+
23+
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
24+
WORKDIR /tests
25+
CMD CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test ./...

pkg/collector/collector.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const (
1212
ContainerLogs
1313
//CustomResource defines CustomResource Collector Type
1414
CustomResource
15+
//CustomResource defines CustomResource Collector Type
16+
CustomResourceV2
1517
//Exec defines Exec Collector Type
1618
Exec
1719
//Helm defines Helm Collector Type
@@ -34,7 +36,7 @@ const (
3436

3537
// Name returns type name
3638
func (t Type) name() string {
37-
return [...]string{"dns", "containerlogs", "customresource", "exec", "helm", "iptables", "kubeletcmd", "kubeobjects", "networkoutbound", "nodelogs", "systemlogs", "systemperf"}[t]
39+
return [...]string{"dns", "containerlogs", "customresource", "customresourcev2", "exec", "helm", "iptables", "kubeletcmd", "kubeobjects", "networkoutbound", "nodelogs", "systemlogs", "systemperf"}[t]
3840
}
3941

4042
// BaseCollector defines Base Collector

pkg/collector/customresource_collector.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package collector
22

33
import (
4+
"path/filepath"
5+
"strings"
6+
47
"github.com/Azure/aks-periscope/pkg/interfaces"
8+
"github.com/Azure/aks-periscope/pkg/utils"
59
)
610

711
// CustomResourceCollector defines a CustomResources Collector struct
@@ -23,5 +27,33 @@ func NewCustomResourceCollector(exporter interfaces.Exporter) *CustomResourceCol
2327

2428
// Collect implements the interface method
2529
func (collector *CustomResourceCollector) Collect() error {
30+
rootPath, err := utils.CreateCollectorDir(collector.GetName())
31+
32+
output, err := utils.RunCommandOnContainer("kubectl", "get", "namespace", "--output=jsonpath={.items..metadata.name}")
33+
if err != nil {
34+
return err
35+
}
36+
namespaces := strings.Split(output, " ")
37+
for _, namespace := range namespaces {
38+
output, err = utils.RunCommandOnContainer("kubectl", "-n", namespace, "get", "crd", "--output=jsonpath={.items..metadata.name}")
39+
if err != nil {
40+
return err
41+
}
42+
43+
objects := strings.Split(output, " ")
44+
for _, object := range objects {
45+
customResourceFile := filepath.Join(rootPath, namespace+"_"+"crd"+"_"+object)
46+
output, err := utils.RunCommandOnContainer("kubectl", "-n", namespace, "describe", "crd", object)
47+
if err != nil {
48+
return err
49+
}
50+
err = utils.WriteToFile(customResourceFile, output)
51+
if err != nil {
52+
return err
53+
}
54+
55+
collector.AddToCollectorFiles(customResourceFile)
56+
}
57+
}
2658
return nil
2759
}

pkg/collector/exec_collector.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package collector
22

33
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
48
"github.com/Azure/aks-periscope/pkg/interfaces"
9+
"github.com/Azure/aks-periscope/pkg/utils"
510
)
611

712
// ExecCollector defines a Exec Collector struct
@@ -23,5 +28,31 @@ func NewExecCollector(exporter interfaces.Exporter) *ExecCollector {
2328

2429
// Collect implements the interface method
2530
func (collector *ExecCollector) Collect() error {
31+
rootPath, err := utils.CreateCollectorDir(collector.GetName())
32+
if err != nil {
33+
return err
34+
}
35+
namespaces := strings.Fields(os.Getenv("DIAGNOSTIC_EXEC_LIST"))
36+
for _, namespace := range namespaces {
37+
output, err := utils.RunCommandOnContainer("kubectl", "get", "-n", namespace, "pods", "--output=jsonpath={.items..metadata.name}")
38+
if err != nil {
39+
return err
40+
}
41+
pods := strings.Split(output, " ")
42+
43+
for _, pod := range pods {
44+
execLog := filepath.Join(rootPath, namespace+"_"+pod)
45+
output, err := utils.RunCommandOnContainer("kubectl", "-n", namespace, "exec", pod, "--", "curl", "example.com")
46+
if err != nil {
47+
return err
48+
}
49+
err = utils.WriteToFile(execLog, output)
50+
if err != nil {
51+
return err
52+
}
53+
54+
collector.AddToCollectorFiles(execLog)
55+
}
56+
}
2657
return nil
2758
}

pkg/collector/helm_collector.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package collector
22

33
import (
4+
"path/filepath"
5+
46
"github.com/Azure/aks-periscope/pkg/interfaces"
7+
"github.com/Azure/aks-periscope/pkg/utils"
58
)
69

710
// HelmCollector defines a Helm Collector struct
811
type HelmCollector struct {
912
BaseCollector
1013
}
1114

12-
var _ interfaces.Collector = &IPTablesCollector{}
15+
var _ interfaces.Collector = &HelmCollector{}
1316

1417
// NewHelmCollector is a constructor
1518
func NewHelmCollector(exporter interfaces.Exporter) *HelmCollector {
@@ -23,5 +26,43 @@ func NewHelmCollector(exporter interfaces.Exporter) *HelmCollector {
2326

2427
// Collect implements the interface method
2528
func (collector *HelmCollector) Collect() error {
29+
rootPath, err := utils.CreateCollectorDir(collector.GetName())
30+
if err != nil {
31+
return err
32+
}
33+
helmListFile := filepath.Join(rootPath, "helm_list")
34+
output, err := utils.RunCommandOnContainer("helm", "list", "--all-namespaces")
35+
if err != nil {
36+
return err
37+
}
38+
39+
err = utils.WriteToFile(helmListFile, output)
40+
if err != nil {
41+
return err
42+
}
43+
44+
collector.AddToCollectorFiles(helmListFile)
45+
46+
helmHistoryFile := filepath.Join(rootPath, collector.GetName())
47+
output, err = utils.RunCommandOnContainer("helm", "history", "-n", "default", "azure-arc")
48+
if err != nil {
49+
return err
50+
}
51+
err = utils.WriteToFile(helmHistoryFile, output)
52+
if err != nil {
53+
return err
54+
}
55+
56+
helmHistoryFile := filepath.Join(rootPath, collector.GetName())
57+
output, err = utils.RunCommandOnContainer("helm", "history", "-n", "default", "azure-arc")
58+
if err != nil {
59+
return err
60+
}
61+
err = utils.WriteToFile(helmHistoryFile, output)
62+
if err != nil {
63+
return err
64+
}
65+
66+
collector.AddToCollectorFiles(helmHistoryFile)
2667
return nil
2768
}

0 commit comments

Comments
 (0)