Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm feature #54

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor github.com/Azure/aks-periscope/cmd/aks-periscope

FROM alpine
RUN apk --no-cache add ca-certificates
RUN apk --no-cache add ca-certificates curl openssl bash
ADD https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 \
Tatsinnit marked this conversation as resolved.
Show resolved Hide resolved
&& chmod +x get_helm.sh \
&& ./get_helm.sh
RUN mkdir /app
WORKDIR /app
COPY --from=builder /app/aks-periscope .
Expand Down
38 changes: 26 additions & 12 deletions cmd/aks-periscope/aks-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"log"
"os"
"strings"
"sync"

Expand All @@ -22,25 +23,38 @@ func main() {
log.Printf("Failed to create CRD: %+v", err)
}

clusterType := os.Getenv("CLUSTER_TYPE")

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

if strings.EqualFold(clusterType, "connectedCluster") {
collectors = append(collectors, containerLogsCollector)
Tatsinnit marked this conversation as resolved.
Show resolved Hide resolved
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)
collectors = append(collectors, kubeletCmdCollector)
collectors = append(collectors, systemPerfCollector)
}

for _, c := range collectors {
waitgroup.Add(1)
Expand Down
12 changes: 11 additions & 1 deletion deployment/aks-periscope.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
name: aks-periscope-role
rules:
- apiGroups: ["","metrics.k8s.io"]
resources: ["pods", "nodes"]
resources: ["pods", "nodes", "secrets"]
verbs: ["get", "watch", "list"]
- apiGroups: ["aks-periscope.azure.github.com"]
resources: ["diagnostics"]
Expand Down Expand Up @@ -80,6 +80,8 @@ spec:
name: kubeobjects-config
- configMapRef:
name: nodelogs-config
- configMapRef:
name: clustertype-config
- secretRef:
name: azureblob-secret
volumeMounts:
Expand Down Expand Up @@ -132,6 +134,14 @@ metadata:
data:
DIAGNOSTIC_NODELOGS_LIST: /var/log/azure/cluster-provision.log /var/log/cloud-init.log
---
apiVersion: v1
kind: ConfigMap
metadata:
name: clustertype-config
namespace: aks-periscope
data:
CLUSTER_TYPE: "managedCluster" # <custom flag>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A request: would it be possible to use a generic name here like FEATURE_FLAGS? Specifically because in PR #48, based on feedback from @Tatsinnit, we are looking to reuse your flag for adding in 2 new collectors (SMI and OSM) that are not based on cluster type.

Ref: https://github.com/Azure/aks-periscope/pull/48/files#diff-cdb15eaf022fc76984176a66a52183b8c3cb0710176cc9349519c5d43fb1d2ffR49-R58

Copy link
Member

@Tatsinnit Tatsinnit May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Let's do this change in your PR, I think ARC folks have almost completed this, so as it looks like only thing you need is renaming this flag and we can do that as part of the OSM x SMI workitem.

cc: @safeermohammed - what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. We can make that change as a fast follow once this gets merged

cc: @shalier

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down
4 changes: 3 additions & 1 deletion pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
DNS Type = iota
// ContainerLogs defines ContainerLogs Collector Type
ContainerLogs
//Helm defines Helm Collector Type
Helm
// IPTables defines IPTables Collector Type
IPTables
// KubeletCmd defines KubeletCmd Collector Type
Expand All @@ -28,7 +30,7 @@ const (

// Name returns type name
func (t Type) name() string {
return [...]string{"dns", "containerlogs", "iptables", "kubeletcmd", "kubeobjects", "networkoutbound", "nodelogs", "systemlogs", "systemperf"}[t]
return [...]string{"dns", "containerlogs", "helm", "iptables", "kubeletcmd", "kubeobjects", "networkoutbound", "nodelogs", "systemlogs", "systemperf"}[t]
}

// BaseCollector defines Base Collector
Expand Down
61 changes: 61 additions & 0 deletions pkg/collector/helm_collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package collector

import (
"path/filepath"

"github.com/Azure/aks-periscope/pkg/interfaces"
"github.com/Azure/aks-periscope/pkg/utils"
)

// HelmCollector defines a Helm Collector struct
type HelmCollector struct {
BaseCollector
}

var _ interfaces.Collector = &HelmCollector{}
sophsoph321 marked this conversation as resolved.
Show resolved Hide resolved

// NewHelmCollector is a constructor
func NewHelmCollector(exporter interfaces.Exporter) *HelmCollector {
return &HelmCollector{
BaseCollector: BaseCollector{
collectorType: Helm,
exporter: exporter,
},
}
}

// Collect implements the interface method
func (collector *HelmCollector) Collect() error {
rootPath, err := utils.CreateCollectorDir(collector.GetName())
if err != nil {
return err
}

helmListFile := filepath.Join(rootPath, "helm_list")
helm_list_output, helm_list_err := utils.RunCommandOnContainer("helm", "list", "--all-namespaces")
if helm_list_err != nil {
return helm_list_err
}

helm_list_err = utils.WriteToFile(helmListFile, helm_list_output)
if helm_list_err != nil {
return helm_list_err
}

collector.AddToCollectorFiles(helmListFile)

helmHistoryFile := filepath.Join(rootPath, "helm_history")
helm_history_output, helm_history_err := utils.RunCommandOnContainer("helm", "history", "-n", "default", "azure-arc")
if helm_history_err != nil {
return helm_history_err
}

helm_history_err = utils.WriteToFile(helmHistoryFile, helm_history_output)
if helm_history_err != nil {
return helm_history_err
}

collector.AddToCollectorFiles(helmHistoryFile)

return nil
}