Skip to content

Commit

Permalink
Merge master into release branch (#589)
Browse files Browse the repository at this point in the history
* Name filtering and output format for the components command

* Adding component output unit test

* Adding case-insensitivity to component an configuration name filtering

* Generate checksum files on release. (#586)

* add renewed headers (#588)

Co-authored-by: Phil Kedy <phil.kedy@gmail.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: Yaron Schneider <yaronsc@microsoft.com>
  • Loading branch information
4 people authored Feb 11, 2021
1 parent b589bbf commit 509b3c9
Show file tree
Hide file tree
Showing 66 changed files with 417 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/get_release_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/dapr_cli.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------

Expand Down Expand Up @@ -102,6 +102,10 @@ jobs:
REL_VER=`cat ${REL_VERSION_FILE}`
echo "REL_VERSION=${REL_VER}" >> $GITHUB_ENV
rm -f ${REL_VERSION_FILE}
- name: generate checksum files
run: cd ${ARTIFACT_DIR} && for i in *; do sha256sum -b $i > "$i.sha256"; done && cd -
- name: lists artifacts
run: ls -l ${{ env.ARTIFACT_DIR }}
- name: publish binaries to github
if: startswith(github.ref, 'refs/tags/v')
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_notification.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) Microsoft Corporation.
Copyright (c) Microsoft Corporation and Dapr Contributors.

MIT License

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
21 changes: 9 additions & 12 deletions cmd/components.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand All @@ -10,29 +10,24 @@ import (

"github.com/dapr/cli/pkg/kubernetes"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/utils"
"github.com/gocarina/gocsv"
"github.com/spf13/cobra"
)

var (
componentsName string
componentsOutputFormat string
)

var ComponentsCmd = &cobra.Command{
Use: "components",
Short: "List all Dapr components. Supported platforms: Kubernetes",
Run: func(cmd *cobra.Command, args []string) {
if kubernetesMode {
components, err := kubernetes.Components()
if err != nil {
print.FailureStatusEvent(os.Stdout, err.Error())
os.Exit(1)
}

table, err := gocsv.MarshalString(components)
err := kubernetes.PrintComponents(componentsName, componentsOutputFormat)
if err != nil {
print.FailureStatusEvent(os.Stdout, err.Error())
os.Exit(1)
}

utils.PrintTable(table)
}
},
Example: `
Expand All @@ -42,6 +37,8 @@ dapr components -k
}

func init() {
ComponentsCmd.Flags().StringVarP(&componentsName, "name", "n", "", "The components name to be printed (optional)")
ComponentsCmd.Flags().StringVarP(&componentsOutputFormat, "output", "o", "list", "Output format (options: json or yaml or list)")
ComponentsCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "List all Dapr components in a Kubernetes cluster")
ComponentsCmd.Flags().BoolP("help", "h", false, "Print this help message")
ComponentsCmd.MarkFlagRequired("kubernetes")
Expand Down
2 changes: 1 addition & 1 deletion cmd/configurations.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/dapr.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/invoke.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/logs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/mtls.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/publish.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/stop.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/uninstall.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
gopkg.in/yaml.v2 v2.3.0
helm.sh/helm/v3 v3.4.0
k8s.io/api v0.20.0
k8s.io/apiextensions-apiserver v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/cli-runtime v0.20.0
k8s.io/client-go v0.20.0
Expand Down
2 changes: 1 addition & 1 deletion install/install.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------
param (
Expand Down
2 changes: 1 addition & 1 deletion install/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pkg/age/age.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

Expand Down
59 changes: 48 additions & 11 deletions pkg/kubernetes/components.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------

package kubernetes

import (
"io"
"os"
"strings"

"github.com/dapr/cli/pkg/age"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/dapr/cli/pkg/age"
"github.com/dapr/cli/utils"
v1alpha1 "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
)

// ComponentsOutput represent a Dapr component.
Expand All @@ -22,20 +27,51 @@ type ComponentsOutput struct {
Age string `csv:"AGE"`
}

// List outputs all Dapr components.
func Components() ([]ComponentsOutput, error) {
client, err := DaprClient()
// PrintComponents prints all Dapr components.
func PrintComponents(name, outputFormat string) error {
return writeComponents(os.Stdout, func() (*v1alpha1.ComponentList, error) {
client, err := DaprClient()
if err != nil {
return nil, err
}

return client.ComponentsV1alpha1().Components(meta_v1.NamespaceAll).List(meta_v1.ListOptions{})
}, name, outputFormat)
}

func writeComponents(writer io.Writer, getConfigFunc func() (*v1alpha1.ComponentList, error), name, outputFormat string) error {
confs, err := getConfigFunc()
if err != nil {
return nil, err
return err
}

comps, err := client.ComponentsV1alpha1().Components(meta_v1.NamespaceAll).List(meta_v1.ListOptions{})
if err != nil {
return nil, err
filtered := []v1alpha1.Component{}
filteredSpecs := []configurationDetailedOutput{}
for _, c := range confs.Items {
confName := c.GetName()
if confName == "daprsystem" {
continue
}

if name == "" || strings.EqualFold(confName, name) {
filtered = append(filtered, c)
filteredSpecs = append(filteredSpecs, configurationDetailedOutput{
Name: confName,
Spec: c.Spec,
})
}
}

if outputFormat == "" || outputFormat == "list" {
return printComponentList(writer, filtered)
}

return utils.PrintDetail(writer, outputFormat, filteredSpecs)
}

func printComponentList(writer io.Writer, list []v1alpha1.Component) error {
co := []ComponentsOutput{}
for _, c := range comps.Items {
for _, c := range list {
co = append(co, ComponentsOutput{
Name: c.GetName(),
Type: c.Spec.Type,
Expand All @@ -45,5 +81,6 @@ func Components() ([]ComponentsOutput, error) {
Scopes: strings.Join(c.Scopes, ","),
})
}
return co, nil

return utils.MarshalAndWriteTable(writer, co)
}
Loading

0 comments on commit 509b3c9

Please sign in to comment.