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

set-log-severity-for-managed-cluster-components #154

Open
wants to merge 84 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
86da5eb
Modifying set method to use optional flags.
AdamSadek Sep 3, 2023
f121196
Removed instance and DC creation.
AdamSadek Sep 3, 2023
e532ec7
Forgot to check for clusterType
AdamSadek Sep 3, 2023
0341d31
Fixing name of func and adding clusterType to function arguments
AdamSadek Sep 3, 2023
f2ab169
removing instance as it will now use the passed in dc
AdamSadek Sep 3, 2023
5adfc85
experimenting
AdamSadek Sep 3, 2023
eeb82ae
Making adjustments
AdamSadek Sep 3, 2023
d495e8b
importing apierrors & metav1
AdamSadek Sep 3, 2023
428c6d6
fixing managed dc
AdamSadek Sep 3, 2023
0191171
directly setting ClusterName and ClusterType?
AdamSadek Sep 3, 2023
bd32587
Resolving syntax errors
AdamSadek Sep 3, 2023
193ac05
removing comma
AdamSadek Sep 3, 2023
289a65b
Merge branch 'projectsveltos:main' into set-log-severity-for-managed-…
AdamSadek May 14, 2024
8e1328c
extended log command to set severity for components in managed clusters
AdamSadek May 14, 2024
2a6c3c5
handle log-level command for managed clusters
AdamSadek May 14, 2024
3ce2647
argument mismatch fix, undefined instance fix, correct GetClientForMa…
AdamSadek May 14, 2024
66995bd
error handling in set function, logical check in update operations.
AdamSadek May 14, 2024
e5aabdd
new approach
AdamSadek May 14, 2024
dedd3f9
not enough arguments fix attempt
AdamSadek May 14, 2024
0b2e089
dealing with some errors
AdamSadek May 14, 2024
1055acf
adding new params to test
AdamSadek May 14, 2024
0a6af09
creating GetDebuggingConfiguration and adding dynamic switching of cl…
AdamSadek May 14, 2024
65597c4
reverting changes in client.go as I misunderstood a part and maing ch…
AdamSadek May 14, 2024
47e6693
update params in test files
AdamSadek May 14, 2024
d438fe7
I thought there was a typo
AdamSadek May 14, 2024
c403cfd
unset missing the new params!
AdamSadek May 14, 2024
c556426
lint erros
AdamSadek May 14, 2024
346348c
new approach in utils.go
AdamSadek May 14, 2024
7c87767
param order fix
AdamSadek May 14, 2024
a3ccc18
reducing errors
AdamSadek May 14, 2024
5e8b48b
removing extra params
AdamSadek May 15, 2024
f7433c0
removing nil return from collectlogconfig
AdamSadek May 15, 2024
b83719b
trying a new fix
AdamSadek May 15, 2024
9892c79
i dont think theres a point in returning the namespace and clusternam…
AdamSadek May 15, 2024
d7697d3
tried a new approach. should be better
AdamSadek May 15, 2024
41ef5a4
making change sin debuggingconfig.go file
AdamSadek May 15, 2024
a6be678
making the changes in the debbuging config test file
AdamSadek May 15, 2024
cf49a5d
should fix the failing tests
AdamSadek May 15, 2024
8e9bda0
mispell is on purpose, i keep forgetting!
AdamSadek May 15, 2024
ed1f8e8
fixing lint errors to make test vars constants
AdamSadek May 15, 2024
5cd2a90
forgot to add change in utils.go debug config section
AdamSadek May 21, 2024
0cbc9bb
reverting change
AdamSadek May 21, 2024
df3c66e
adding clusterType and making additional changes
AdamSadek May 21, 2024
ee8574a
clusterproxy.GetSveltosKubernetesClient to get the client pointing to…
AdamSadek May 21, 2024
6791133
might be an issue with k8sAccess redeclaration
AdamSadek May 21, 2024
55bc06d
Misunderstanding. This should be better
AdamSadek May 21, 2024
b405b7b
adding cluster type to req object
AdamSadek May 21, 2024
b2c4773
resolving some errors
AdamSadek May 21, 2024
604e82c
adding logger as param
AdamSadek May 21, 2024
f00a1ab
getting logger in a different way
AdamSadek May 21, 2024
94f6389
logger is being tedious. debugging
AdamSadek May 21, 2024
0f6ee03
fixing logger
AdamSadek May 21, 2024
353af46
new approach to get logger
AdamSadek May 22, 2024
bfdb2dc
getting logger new approach
AdamSadek May 22, 2024
b6ea9d7
new approach for logger
AdamSadek May 22, 2024
d78fbab
Passing it as a parameter
AdamSadek May 22, 2024
459f5da
using correct GetKubernetesClient
AdamSadek May 23, 2024
7c97e41
getting logger
AdamSadek May 23, 2024
09f00d2
adding defaultInstanceName back
AdamSadek May 23, 2024
031b75e
attempting to resolve error in test for debuggingconfig
AdamSadek May 23, 2024
4d6ef55
attempt to fix test, different approach
AdamSadek May 23, 2024
b0d9a07
reverting change
AdamSadek May 23, 2024
4dbb7be
adding values instead of empty
AdamSadek May 23, 2024
001552e
testing fix
AdamSadek May 23, 2024
acff7cc
testing dc name
AdamSadek May 23, 2024
0559217
no need for addition in set_test
AdamSadek May 23, 2024
2a70ba7
adding cluster type and namespace to DC
AdamSadek May 23, 2024
66f2694
adding type and namespace to DC
AdamSadek May 23, 2024
cdf8ead
Testing new approach for debuggingconfiguratgions
AdamSadek May 23, 2024
ac53608
removing Type
AdamSadek May 23, 2024
9ac2877
new fixes
AdamSadek May 23, 2024
92b4f55
reveritng back to previous change.
AdamSadek May 23, 2024
c1a6dfc
reverting back to previous version
AdamSadek May 23, 2024
9973b4e
Changing expect test from Namespace to Name
AdamSadek May 23, 2024
c52e8b4
Reading optional arguments correctly.
AdamSadek May 28, 2024
b66c01b
Syntax fix
AdamSadek May 28, 2024
ce63ac2
Reading optional arguments correctly for show.go
AdamSadek May 28, 2024
2bdfccb
Merge pull request #250 from gianlucam76/main
gianlucam76 May 29, 2024
089981f
Merge branch 'projectsveltos:main' into set-log-severity-for-managed-…
AdamSadek May 31, 2024
9116e3d
Removed instance and DC creation.
AdamSadek Sep 3, 2023
44dfbdc
extended log command to set severity for components running in manage…
AdamSadek Jun 5, 2024
34eeae3
Merge branch 'set-log-severity-for-managed-cluster-components' of htt…
AdamSadek Jun 5, 2024
b692f12
Delete id_rsa
AdamSadek Jun 5, 2024
96ce14f
Delete id_rsa.pub
AdamSadek Jun 5, 2024
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
39 changes: 27 additions & 12 deletions internal/commands/loglevel/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"strings"

docopt "github.com/docopt/docopt-go"

libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1"
"github.com/projectsveltos/sveltosctl/internal/utils"
)

func updateDebuggingConfiguration(ctx context.Context, logSeverity libsveltosv1alpha1.LogLevel,
component string) error {
component, namespace, clusterName, clusterType string) error {

cc, err := collectLogLevelConfiguration(ctx)
cc, err := collectLogLevelConfiguration(ctx, namespace, clusterName, clusterType)
if err != nil {
return nil
}
Expand Down Expand Up @@ -62,22 +62,25 @@ func updateDebuggingConfiguration(ctx context.Context, logSeverity libsveltosv1a
)
}

return updateLogLevelConfiguration(ctx, spec)
return updateLogLevelConfiguration(ctx, spec, namespace, clusterName, clusterType)
}

// Set displays/changes log verbosity for a given component
func Set(ctx context.Context, args []string) error {
doc := `Usage:
sveltosctl log-level set --component=<name> (--info|--debug|--verbose)
sveltosctl log-level set --component=<name> [--namespace=<namespace>] [--cluster=<cluster-name>] [--cluster-type=<cluster-type>] (--info|--debug|--verbose)
Options:
-h --help Show this screen.
--component=<name> Name of the component for which log severity is being set.
--info Set log severity to info.
--debug Set log severity to debug.
--verbose Set log severity to verbose.
-h --help Show this screen.
--component=<name> Name of the component for which log severity is being set.
--namespace=<namespace> Namespace of the cluster.
--cluster=<cluster-name> Name of the cluster.
--cluster-type=<cluster-type> Type of the cluster (Capi or Sveltos).
--info Set log severity to info.
--debug Set log severity to debug.
--verbose Set log severity to verbose.

Description:
The log-level set command set log severity for the specified component.
The log-level set command sets log severity for the specified component in the specified cluster.
`
parsedArgs, err := docopt.ParseArgs(doc, nil, "1.0")
if err != nil {
Expand All @@ -94,6 +97,18 @@ Description:
if passedComponent := parsedArgs["--component"]; passedComponent != nil {
component = passedComponent.(string)
}
namespace := ""
if passedNamespace := parsedArgs["--namespace"]; passedNamespace != nil {
namespace = passedNamespace.(string)
}
clusterName := ""
if passedClusterName := parsedArgs["--cluster"]; passedClusterName != nil {
clusterName = passedClusterName.(string)
}
clusterType := ""
if passedClusterType := parsedArgs["--cluster-type"]; passedClusterType != nil {
clusterType = passedClusterType.(string)
}

info := parsedArgs["--info"].(bool)
debug := parsedArgs["--debug"].(bool)
Expand All @@ -108,5 +123,5 @@ Description:
logSeverity = libsveltosv1alpha1.LogLevelVerbose
}

return updateDebuggingConfiguration(ctx, logSeverity, component)
return updateDebuggingConfiguration(ctx, logSeverity, component, namespace, clusterName, clusterType)
}
9 changes: 4 additions & 5 deletions internal/commands/loglevel/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ import (

var _ = Describe("Set", func() {
It("set updates default DebuggingConfiguration instance", func() {

scheme, err := utils.GetScheme()
Expect(err).To(BeNil())
c := fake.NewClientBuilder().WithScheme(scheme).Build()

utils.InitalizeManagementClusterAcces(scheme, nil, nil, c)
Expect(loglevel.UpdateDebuggingConfiguration(context.TODO(), libsveltosv1alpha1.LogLevelDebug,
string(libsveltosv1alpha1.ComponentAddonManager))).To(Succeed())
string(libsveltosv1alpha1.ComponentAddonManager), "", "", "")).To(Succeed())

k8sAccess := utils.GetAccessInstance()

currentDC, err := k8sAccess.GetDebuggingConfiguration(context.TODO())
currentDC, err := k8sAccess.GetDebuggingConfiguration(context.TODO(), "", "", "")
Expect(err).To(BeNil())
Expect(currentDC).ToNot(BeNil())
Expect(currentDC.Spec.Configuration).ToNot(BeNil())
Expand All @@ -50,8 +49,8 @@ var _ = Describe("Set", func() {
Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1alpha1.LogLevelDebug))

Expect(loglevel.UpdateDebuggingConfiguration(context.TODO(), libsveltosv1alpha1.LogLevelInfo,
string(libsveltosv1alpha1.ComponentAddonManager))).To(Succeed())
currentDC, err = k8sAccess.GetDebuggingConfiguration(context.TODO())
string(libsveltosv1alpha1.ComponentAddonManager), "", "", "")).To(Succeed())
currentDC, err = k8sAccess.GetDebuggingConfiguration(context.TODO(), "", "", "")
Expect(err).To(BeNil())
Expect(currentDC).ToNot(BeNil())
Expect(currentDC.Spec.Configuration).ToNot(BeNil())
Expand Down
31 changes: 24 additions & 7 deletions internal/commands/loglevel/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/olekukonko/tablewriter"
)

func showLogSettings(ctx context.Context) error {
componentConfiguration, err := collectLogLevelConfiguration(ctx)
func showLogSettings(ctx context.Context, namespace, clusterName, clusterType string) error {
componentConfiguration, err := collectLogLevelConfiguration(ctx, namespace, clusterName, clusterType)
if err != nil {
return err
}
Expand All @@ -52,12 +52,15 @@ func showLogSettings(ctx context.Context) error {
// Show displays information about log verbosity (if set)
func Show(ctx context.Context, args []string) error {
doc := `Usage:
sveltosctl log-level show
sveltosctl log-level show [--namespace=<namespace>] [--cluster=<cluster-name>] [--cluster-type=<cluster-type>]
Options:
-h --help Show this screen.
-h --help Show this screen.
--namespace=<namespace> Namespace of the cluster.
--cluster=<cluster-name> Name of the cluster.
--cluster-type=<cluster-type> Type of the cluster (Capi or Sveltos).

Description:
The log-level show command shows information about current log verbosity.
The log-level show command shows information about current log verbosity in the specified cluster.
`
parsedArgs, err := docopt.ParseArgs(doc, nil, "1.0")
if err != nil {
Expand All @@ -70,5 +73,19 @@ Description:
return nil
}

return showLogSettings(ctx)
}
namespace := ""
if passedNamespace := parsedArgs["--namespace"]; passedNamespace != nil {
namespace = passedNamespace.(string)
}
clusterName := ""
if passedClusterName := parsedArgs["--cluster"]; passedClusterName != nil {
clusterName = passedClusterName.(string)
}
clusterType := ""
if passedClusterType := parsedArgs["--cluster-type"]; passedClusterType != nil {
clusterType = passedClusterType.(string)
}


return showLogSettings(ctx, namespace, clusterName, clusterType)
}
8 changes: 4 additions & 4 deletions internal/commands/loglevel/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

var _ = Describe("Show", func() {
It("show displays current log level settings", func() {
It("show displays current log level settings in managed cluster", func() {
dc := getDebuggingConfiguration()
dc.Spec.Configuration = []libsveltosv1alpha1.ComponentConfiguration{
{Component: libsveltosv1alpha1.ComponentClassifier, LogLevel: libsveltosv1alpha1.LogLevelDebug},
Expand All @@ -52,7 +52,7 @@ var _ = Describe("Show", func() {
c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(initObjects...).Build()

utils.InitalizeManagementClusterAcces(scheme, nil, nil, c)
err = loglevel.ShowLogSettings(context.TODO())
err = loglevel.ShowLogSettings(context.TODO(), "", "", "")
Expect(err).To(BeNil())

w.Close()
Expand All @@ -61,7 +61,7 @@ var _ = Describe("Show", func() {
Expect(err).To(BeNil())

/*
// This is an example of how the table needs to look like
// This is an example of how the table needs to look like
+------------------+---------------+
| COMPONENT | VERBOSIRY |
+------------------+---------------+
Expand All @@ -82,4 +82,4 @@ var _ = Describe("Show", func() {
Expect(found).To(BeTrue())
os.Stdout = old
})
})
})
34 changes: 24 additions & 10 deletions internal/commands/loglevel/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (
"strings"

docopt "github.com/docopt/docopt-go"

libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1"
)

func unsetDebuggingConfiguration(ctx context.Context, component string) error {
cc, err := collectLogLevelConfiguration(ctx)
func unsetDebuggingConfiguration(ctx context.Context, component, namespace, clusterName, clusterType string) error {
cc, err := collectLogLevelConfiguration(ctx, namespace, clusterName, clusterType)
if err != nil {
return nil
}
Expand All @@ -50,21 +49,24 @@ func unsetDebuggingConfiguration(ctx context.Context, component string) error {
}

if found {
return updateLogLevelConfiguration(ctx, spec)
return updateLogLevelConfiguration(ctx, spec, namespace, clusterName, clusterType)
}
return nil
}

// Unset resets log verbosity for a given component
func Unset(ctx context.Context, args []string) error {
doc := `Usage:
sveltosctl log-level unset --component=<name>
sveltosctl log-level unset --component=<name> [--namespace=<namespace>] [--cluster=<cluster-name>] [--cluster-type=<cluster-type>]
Options:
-h --help Show this screen.
--component=<name> Name of the component for which log severity is being set.
-h --help Show this screen.
--component=<name> Name of the component for which log severity is being unset.
--namespace=<namespace> Namespace of the cluster.
--cluster=<cluster-name> Name of the cluster.
--cluster-type=<cluster-type> Type of the cluster (Capi or Sveltos).

Description:
The log-level set command set log severity for the specified component.
The log-level unset command unset log severity for the specified component in the specified cluster.
`
parsedArgs, err := docopt.ParseArgs(doc, nil, "1.0")
if err != nil {
Expand All @@ -81,6 +83,18 @@ Description:
if passedComponent := parsedArgs["--component"]; passedComponent != nil {
component = passedComponent.(string)
}
namespace := ""
if passedNamespace := parsedArgs["--namespace"]; passedNamespace != nil {
namespace = passedNamespace.(string)
}
clusterName := ""
if passedClusterName := parsedArgs["--cluster"]; passedClusterName != nil {
clusterName = passedClusterName.(string)
}
clusterType := ""
if passedClusterType := parsedArgs["--cluster-type"]; passedClusterType != nil {
clusterType = passedClusterType.(string)
}

return unsetDebuggingConfiguration(ctx, component)
}
return unsetDebuggingConfiguration(ctx, component, namespace, clusterName, clusterType)
}
8 changes: 4 additions & 4 deletions internal/commands/loglevel/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var _ = Describe("Unset", func() {
It("unset removes log level settings", func() {
It("unset removes log level settings in managed cluster", func() {
dc := getDebuggingConfiguration()
dc.Spec.Configuration = []libsveltosv1alpha1.ComponentConfiguration{
{Component: libsveltosv1alpha1.ComponentClassifier, LogLevel: libsveltosv1alpha1.LogLevelInfo},
Expand All @@ -45,17 +45,17 @@ var _ = Describe("Unset", func() {

utils.InitalizeManagementClusterAcces(scheme, nil, nil, c)

Expect(loglevel.UnsetDebuggingConfiguration(context.TODO(), string(libsveltosv1alpha1.ComponentClassifier))).To(Succeed())
Expect(loglevel.UnsetDebuggingConfiguration(context.TODO(), string(libsveltosv1alpha1.ComponentClassifier), "", "", "")).To(Succeed())

k8sAccess := utils.GetAccessInstance()

currentDC, err := k8sAccess.GetDebuggingConfiguration(context.TODO())
currentDC, err := k8sAccess.GetDebuggingConfiguration(context.TODO(), "", "", "")
Expect(err).To(BeNil())
Expect(currentDC).ToNot(BeNil())
Expect(currentDC.Spec.Configuration).ToNot(BeNil())
Expect(len(currentDC.Spec.Configuration)).To(Equal(1))
Expect(currentDC.Spec.Configuration[0].Component).To(Equal(libsveltosv1alpha1.ComponentAddonManager))
Expect(currentDC.Spec.Configuration[0].LogLevel).To(Equal(libsveltosv1alpha1.LogLevelInfo))

})
})

12 changes: 7 additions & 5 deletions internal/commands/loglevel/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func (c byComponent) Less(i, j int) bool {
return c[i].component < c[j].component
}

func collectLogLevelConfiguration(ctx context.Context) ([]*componentConfiguration, error) {
func collectLogLevelConfiguration(ctx context.Context, namespace, clusterName, clusterType string) ([]*componentConfiguration, error) {
instance := utils.GetAccessInstance()

dc, err := instance.GetDebuggingConfiguration(ctx)
dc, err := instance.GetDebuggingConfiguration(ctx, namespace, clusterName, clusterType)
if err != nil {
if apierrors.IsNotFound(err) {
return make([]*componentConfiguration, 0), nil
Expand All @@ -70,16 +70,18 @@ func collectLogLevelConfiguration(ctx context.Context) ([]*componentConfiguratio
func updateLogLevelConfiguration(
ctx context.Context,
spec []libsveltosv1alpha1.ComponentConfiguration,
namespace, clusterName, clusterType string,
) error {

instance := utils.GetAccessInstance()

dc, err := instance.GetDebuggingConfiguration(ctx)
dc, err := instance.GetDebuggingConfiguration(ctx, namespace, clusterName, clusterType)
if err != nil {
if apierrors.IsNotFound(err) {
dc = &libsveltosv1alpha1.DebuggingConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
Namespace: namespace,
},
}
} else {
Expand All @@ -91,5 +93,5 @@ func updateLogLevelConfiguration(
Configuration: spec,
}

return instance.UpdateDebuggingConfiguration(ctx, dc)
}
return instance.UpdateDebuggingConfiguration(ctx, dc, namespace, clusterName, clusterType)
}
Loading