-
Notifications
You must be signed in to change notification settings - Fork 202
/
configurations.go
60 lines (52 loc) · 1.71 KB
/
configurations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
package kubernetes
import (
"strconv"
"github.com/dapr/cli/pkg/age"
v1alpha1 "github.com/dapr/dapr/pkg/apis/configuration/v1alpha1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ComponentsOutput represent a Dapr component.
type ConfigurtionsOutput struct {
Name string `csv:"Name"`
TracingEnabled bool `csv:"TRACING-ENABLED"`
MTLSEnabled bool `csv:"MTLS-ENABLED"`
WorkloadCertTTL string `csv:"MTLS-WORKLOAD-TTL"`
ClockSkew string `csv:"MTLS-CLOCK-SKEW"`
Age string `csv:"AGE"`
Created string `csv:"CREATED"`
}
// List outputs all Dapr configurations.
func Configurations() ([]ConfigurtionsOutput, error) {
client, err := DaprClient()
if err != nil {
return nil, err
}
confs, err := client.ConfigurationV1alpha1().Configurations(meta_v1.NamespaceAll).List(meta_v1.ListOptions{})
if err != nil {
return nil, err
}
co := []ConfigurtionsOutput{}
for _, c := range confs.Items {
co = append(co, ConfigurtionsOutput{
TracingEnabled: tracingEnabled(c.Spec.TracingSpec),
Name: c.GetName(),
MTLSEnabled: c.Spec.MTLSSpec.Enabled,
WorkloadCertTTL: c.Spec.MTLSSpec.WorkloadCertTTL,
ClockSkew: c.Spec.MTLSSpec.AllowedClockSkew,
Created: c.CreationTimestamp.Format("2006-01-02 15:04.05"),
Age: age.GetAge(c.CreationTimestamp.Time),
})
}
return co, nil
}
func tracingEnabled(spec v1alpha1.TracingSpec) bool {
sr, err := strconv.ParseFloat(spec.SamplingRate, 32)
if err != nil {
return false
}
return sr > 0
}