Skip to content

Commit df90acc

Browse files
authored
Merge pull request #45 from n2h9/chore-add-namespace-resources-based-filtration
chore: add namespace, resources cli param to restrict snapshot to particular resources
2 parents e7c91ac + a720872 commit df90acc

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

cmd/meshsync/main.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
)
1313

1414
func main() {
15-
// var namespace string
16-
// var outputFile string
15+
var namespaces []string
16+
var resources []string
17+
var outputFile string
1718
var duration time.Duration
1819

1920
// Root command for the plugin
@@ -34,14 +35,11 @@ func main() {
3435
log.Info("startings meshsync lib...")
3536
if err := libmeshsync.Run(
3637
log,
37-
// TODO
38-
// add option to libmeshsync to specify
39-
// (the functionality is in place, need to add corresponding WithXXX function):
40-
// - output file name
41-
// - k8s namespace
42-
// - k8s resources list
4338
libmeshsync.WithOutputMode("file"),
39+
libmeshsync.WithOutputFileName(outputFile),
4440
libmeshsync.WithStopAfterDuration(duration),
41+
libmeshsync.WithOnlyK8sResources(resources),
42+
libmeshsync.WithOnlyK8sNamespaces(namespaces...),
4543
); err != nil {
4644
return fmt.Errorf("error running meshsync lib %v", err)
4745
}
@@ -51,9 +49,25 @@ func main() {
5149
},
5250
}
5351

54-
// rootCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "namespace to make a snapshot of (if not specified collects events from all namespaces)")
55-
// rootCmd.Flags().StringVarP(&outputFile, "outputFile", "o", "", "name of a result output file (if not specified produces file with name meshery-cluster-snapshot-YYYYMMDD-NN.yaml)")
56-
rootCmd.Flags().DurationVarP(&duration, "duration", "d", 8*time.Second, "duration of event collection")
52+
rootCmd.Flags().StringVarP(
53+
&outputFile, "file", "f", "",
54+
"Name of the output file.\nIf not specified, the file will be named: meshery-cluster-snapshot-YYYYMMDD-NN.yaml",
55+
)
56+
57+
rootCmd.Flags().DurationVarP(
58+
&duration, "duration", "d", 8*time.Second,
59+
"Duration of event collection (e.g., 8ss, 12s, 1m)",
60+
)
61+
62+
rootCmd.Flags().StringSliceVarP(
63+
&resources, "resources", "r", []string{},
64+
"Comma-separated list of Kubernetes resources to snapshot (case-insensitive).\nFor example: \"pod,deployment,service\"",
65+
)
66+
67+
rootCmd.Flags().StringSliceVarP(
68+
&namespaces, "namespace", "n", []string{},
69+
"One or more namespaces to restrict the snapshot to.\nFor example: \"default,agile-otter\"\nIf not specified, events will be collected from all namespaces",
70+
)
5771

5872
// Execute the command
5973
if err := rootCmd.Execute(); err != nil {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module github.com/meshery-extensions/kubectl-meshsync-snapshot
22

33
go 1.24.0
44

5-
// replace github.com/meshery/meshsync@v0.8.21 ../meshsync
5+
// replace github.com/meshery/meshsync v0.8.22 => ../meshsync
66

77
require (
88
github.com/layer5io/meshkit v0.8.24
9-
github.com/meshery/meshsync v0.8.21
9+
github.com/meshery/meshsync v0.8.22
1010
github.com/sirupsen/logrus v1.9.3
1111
github.com/spf13/cobra v1.9.1
1212
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ github.com/meshery/meshery-operator v0.8.7 h1:SsiyDiPEcibYtoHlYyziwvCcBVfZOCJxq4
239239
github.com/meshery/meshery-operator v0.8.7/go.mod h1:hQEtFKKa5Fr/Mskk6bV5ip3bQ0+3F0u1voYS3XisBp4=
240240
github.com/meshery/meshkit v0.8.32 h1:zXyMLkOXcu2eIVcAxXBfw72vebpq4m8716RBYGhG1fM=
241241
github.com/meshery/meshkit v0.8.32/go.mod h1:Ym2z/5oSQn1jDQr+Qjmm9pBW7jv+8oXqp5+RYr9NXQI=
242-
github.com/meshery/meshsync v0.8.21 h1:w+qQ37YxIkIO4rudS3BRjZ7VMrDCFGNKVK/ucsx8j20=
243-
github.com/meshery/meshsync v0.8.21/go.mod h1:6D/aCTyK8+2VJNFnpJz1IdwvPsdV3ETEJo12VRKfY6I=
242+
github.com/meshery/meshsync v0.8.22 h1:uLymg+riXu7RmLSXo2CbVe02U/swGROJyMZAReQ8gBE=
243+
github.com/meshery/meshsync v0.8.22/go.mod h1:6D/aCTyK8+2VJNFnpJz1IdwvPsdV3ETEJo12VRKfY6I=
244244
github.com/meshery/schemas v0.8.22 h1:JQ7PoEheiXdkIG/h965L+DB7p/JdGEgs3i5r0EniSt4=
245245
github.com/meshery/schemas v0.8.22/go.mod h1:tuAmsG9WJRjZ0Iv12HIAhKZbWpfpkTRjfPNThKbr7HA=
246246
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=

0 commit comments

Comments
 (0)