Skip to content

Commit

Permalink
Trident Autosupport support (#314)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Meade <mr.alex.meade@gmail.com>
  • Loading branch information
clintonk and ameade authored Jul 29, 2020
1 parent 4da6ca9 commit 3d580a1
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Changes since v20.04.0

**IMPORTANT**: If you are upgrading from Trident 19.07 or 19.10 please carefully read [this](https://netapp-trident.readthedocs.io/en/stable-v20.04/kubernetes/upgrading.html).
**IMPORTANT** Trident relies on the [trident-autosupport](https://hub.docker.com/r/netapp/trident-autosupport) sidecar container to periodically send usage and support telemetry data to NetApp by default. Usage of the trident-autosupport project falls under the [NetApp EULA](https://www.netapp.com/us/media/enduser-license-agreement-worldwide.pdf). Automatic sending of this data can be disabled at Trident install time via the "--silence-autosupport" flag.

**Fixes:**
- Disabled automatic iSCSI scans and shortened the iSCSI session replacement timeout. (Issue [#410](https://github.com/NetApp/trident/issues/410))
Expand All @@ -25,6 +26,7 @@
- **Kubernetes:** Added automatic igroup management to ONTAP SAN and ONTAP SAN Economy drivers.
- **Kubernetes:** Added more usage and capacity metrics. (Issue [#400](https://github.com/NetApp/trident/issues/400))
- **Kubernetes:** Added upgrade support to the Trident Operator.
- **Kubernetes:** Automatic NetApp autosupport telemetry reporting via trident-autosupport sidecar, disabled via --silence-autosupport option in tridentctl install command

**Deprecations:**
- **Kubernetes:** Deprecated all of the 'core' metrics because their names are changing.
Expand Down
51 changes: 33 additions & 18 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,25 @@ const (

var (
// CLI flags
generateYAML bool
useYAML bool
silent bool
csi bool
inCluster bool
useIPv6 bool
pvName string
pvcName string
tridentImage string
etcdImage string
kubeletDir string
imageRegistry string
logFormat string
k8sTimeout time.Duration
migratorTimeout time.Duration
generateYAML bool
useYAML bool
silent bool
csi bool
inCluster bool
useIPv6 bool
silenceAutosupport bool
pvName string
pvcName string
tridentImage string
etcdImage string
autosupportImage string
autosupportProxy string
autosupportCustomURL string
kubeletDir string
imageRegistry string
logFormat string
k8sTimeout time.Duration
migratorTimeout time.Duration

// CLI-based K8S client
client k8sclient.Interface
Expand Down Expand Up @@ -126,6 +130,7 @@ func init() {
installCmd.Flags().BoolVar(&csi, "csi", false, "Install CSI Trident (override for Kubernetes 1.13 only, requires feature gates).")
installCmd.Flags().BoolVar(&inCluster, "in-cluster", false, "Run the installer as a pod in the cluster.")
installCmd.Flags().BoolVar(&useIPv6, "use-ipv6", false, "Use IPv6 for Trident's communication.")
installCmd.Flags().BoolVar(&silenceAutosupport, "silence-autosupport", tridentconfig.BuildType != "stable", "Don't send autosupport bundles to NetApp automatically.")

installCmd.Flags().StringVar(&pvcName, "pvc", DefaultPVCName, "The name of the legacy PVC used by Trident, will be migrated to CRDs.")
installCmd.Flags().StringVar(&pvName, "pv", DefaultPVName, "The name of the legacy PV used by Trident, will be migrated to CRDs.")
Expand All @@ -134,6 +139,9 @@ func init() {
installCmd.Flags().StringVar(&logFormat, "log-format", "text", "The Trident logging format (text, json).")
installCmd.Flags().StringVar(&kubeletDir, "kubelet-dir", "/var/lib/kubelet", "The host location of kubelet's internal state.")
installCmd.Flags().StringVar(&imageRegistry, "image-registry", "", "The address/port of an internal image registry.")
installCmd.Flags().StringVar(&autosupportProxy, "autosupport-proxy", "", "The address/port of a proxy for sending Autosupport Telemetry")
installCmd.Flags().StringVar(&autosupportCustomURL, "autosupport-custom-url", "", "")
installCmd.Flags().StringVar(&autosupportImage, "autosupport-image", tridentconfig.DefaultAutosupportImage, "The container image for Autosupport Telemetry")

installCmd.Flags().DurationVar(&k8sTimeout, "k8s-timeout", 180*time.Second, "The timeout for all Kubernetes operations.")
installCmd.Flags().DurationVar(&migratorTimeout, "migrator-timeout", 300*time.Minute, "The timeout for etcd-to-CRD migration.")
Expand Down Expand Up @@ -233,7 +241,7 @@ func discoverInstallationEnvironment() error {
}
log.Debugf("Trident image: %s", tridentImage)

// Default deployment image to what etcd was built with
// Default etcd image to what Trident was built with
if etcdImage == "" {
etcdImage = tridentconfig.BuildEtcdImage

Expand All @@ -245,6 +253,11 @@ func discoverInstallationEnvironment() error {
log.Warningf("Trident was qualified with etcd %s. You appear to be using a different version.", tridentconfig.BuildEtcdVersion)
}

if imageRegistry != "" {
autosupportImage = utils.ReplaceImageRegistry(autosupportImage, imageRegistry)
}
log.Debugf("Autosupport image: %s", autosupportImage)

// Create the Kubernetes client
if client, err = initClient(); err != nil {
return fmt.Errorf("could not initialize Kubernetes client; %v", err)
Expand Down Expand Up @@ -509,7 +522,8 @@ func prepareCSIYAMLFiles() error {
}

deploymentYAML := k8sclient.GetCSIDeploymentYAML(getDeploymentName(true),
tridentImage, csiSidecarRegistry, logFormat, []string{}, labels, nil, Debug, useIPv6, client.ServerVersion())
tridentImage, autosupportImage, autosupportProxy, autosupportCustomURL, csiSidecarRegistry, logFormat,
[]string{}, labels, nil, Debug, useIPv6, silenceAutosupport, client.ServerVersion())
if err = writeFile(deploymentPath, deploymentYAML); err != nil {
return fmt.Errorf("could not write deployment YAML file; %v", err)
}
Expand Down Expand Up @@ -923,7 +937,8 @@ func installTrident() (returnError error) {
} else {
returnError = client.CreateObjectByYAML(
k8sclient.GetCSIDeploymentYAML(getDeploymentName(true),
tridentImage, csiSidecarRegistry, logFormat, []string{}, labels, nil, Debug, useIPv6, client.ServerVersion()))
tridentImage, autosupportImage, autosupportProxy, autosupportCustomURL, csiSidecarRegistry, logFormat, []string{}, labels, nil,
Debug, useIPv6, silenceAutosupport, client.ServerVersion()))
logFields = log.Fields{}
}
if returnError != nil {
Expand Down
47 changes: 42 additions & 5 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const (
CLIKubernetes = "kubectl"
CLIOpenshift = "oc"

PodServer = "127.0.0.1:8000"
PodServer = "127.0.0.1:8000"
PodAutosupportCollector = "127.0.0.1:8003"

ExitCodeSuccess = 0
ExitCodeFailure = 1
Expand Down Expand Up @@ -67,6 +68,8 @@ const (
TridentOperatorLabelKey = "app"
TridentOperatorLabelValue = "operator.trident.netapp.io"
TridentOperatorLabel = TridentOperatorLabelKey + "=" + TridentOperatorLabelValue

AutosupportCollectorURL = "/autosupport/v1"
)

var (
Expand All @@ -76,9 +79,10 @@ var (
TridentPodNamespace string
ExitCode int

Debug bool
Server string
OutputFormat string
Debug bool
Server string
AutosupportCollector string
OutputFormat string

listOpts = metav1.ListOptions{}
updateOpts = metav1.UpdateOptions{}
Expand Down Expand Up @@ -110,13 +114,17 @@ func discoverOperatingMode(_ *cobra.Command) error {

switch OperatingMode {
case ModeDirect:
fmt.Printf("Operating mode = %s, Server = %s\n", OperatingMode, Server)
fmt.Printf("Operating mode = %s, Server = %s, Autosuport server = %s\n",
OperatingMode, Server, AutosupportCollector)
case ModeTunnel:
fmt.Printf("Operating mode = %s, Trident pod = %s, Namespace = %s, CLI = %s\n",
OperatingMode, TridentPodName, TridentPodNamespace, KubernetesCLI)
}
}()

// Use the operating mode to inform the Autosupport collector
defer discoverAutosupportCollector()

var err error

envServer := os.Getenv("TRIDENT_SERVER")
Expand Down Expand Up @@ -176,6 +184,9 @@ func discoverJustOperatingMode(_ *cobra.Command) error {
}
}()

// Use the operating mode to inform the Autosupport server
defer discoverAutosupportCollector()

var err error

envServer := os.Getenv("TRIDENT_SERVER")
Expand Down Expand Up @@ -257,6 +268,21 @@ func getCurrentNamespace() (string, error) {
return namespace, nil
}

func discoverAutosupportCollector() {

switch OperatingMode {
case ModeDirect:
envCollector := os.Getenv("TRIDENT_AUTOSUPPORT_COLLECTOR")
if envCollector != "" {
AutosupportCollector = envCollector
} else {
AutosupportCollector = PodAutosupportCollector
}
case ModeTunnel:
// Nothing to do on the outside
}
}

// getTridentPod returns the name of the Trident pod in the specified namespace
func getTridentPod(namespace, appLabel string) (string, error) {

Expand Down Expand Up @@ -461,6 +487,17 @@ func BaseURL() string {
return url
}

func BaseAutosupportURL() string {

url := fmt.Sprintf("http://%s%s", AutosupportCollector, AutosupportCollectorURL)

if Debug {
fmt.Printf("Trident autosupport URL: %s\n", url)
}

return url
}

func TunnelCommand(commandArgs []string) {

// Build tunnel command to exec command in container
Expand Down
18 changes: 18 additions & 0 deletions cli/cmd/send.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 NetApp, Inc. All Rights Reserved.

package cmd

import "github.com/spf13/cobra"

func init() {
RootCmd.AddCommand(sendCmd)
}

var sendCmd = &cobra.Command{
Use: "send",
Short: "Send a resource from Trident",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := discoverOperatingMode(cmd)
return err
},
}
48 changes: 48 additions & 0 deletions cli/cmd/send_autosupport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020 NetApp, Inc. All Rights Reserved.

package cmd

import (
"fmt"
"net/http"

"github.com/spf13/cobra"

"github.com/netapp/trident/cli/api"
)

func init() {
sendCmd.AddCommand(sendAutosupportCmd)
}

var sendAutosupportCmd = &cobra.Command{
Use: "autosupport",
Short: "Send an Autosupport archive to NetApp",
Aliases: []string{"a", "asup"},
RunE: func(cmd *cobra.Command, args []string) error {

if OperatingMode == ModeTunnel {
command := []string{"send", "autosupport"}
TunnelCommand(append(command, args...))
return nil
} else {
return triggerAutosupport()
}
},
}

func triggerAutosupport() error {

url := BaseAutosupportURL() + "/collector/trident/trigger"

response, responseBody, err := api.InvokeRESTAPI("POST", url, nil, Debug)
if err != nil {
return err
} else if response.StatusCode != http.StatusCreated {
return fmt.Errorf("could not send autosupport: %v", GetErrorFromHTTPResponse(response, responseBody))
} else {
fmt.Println("Autosupport sent.")
}

return nil
}
Loading

0 comments on commit 3d580a1

Please sign in to comment.