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

service profile generation work offline using --ignore-cluster #5482

Merged
merged 6 commits into from
Jan 9, 2021
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
offline profile generation with --ignore-cluster
Signed-off-by: Piyush Singariya <piyushsingariya@gmail.com>
  • Loading branch information
piyushsingariya committed Jan 6, 2021
commit 4f3f808c5c2531b68cbbcafcb871f666facf4994
37 changes: 23 additions & 14 deletions cli/cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type profileOptions struct {
openAPI string
proto string
tap string
ignoreCluster bool
tapDuration time.Duration
tapRouteLimit uint
}
Expand All @@ -32,6 +33,7 @@ func newProfileOptions() *profileOptions {
openAPI: "",
proto: "",
tap: "",
ignoreCluster: false,
tapDuration: 5 * time.Second,
tapRouteLimit: 20,
}
Expand Down Expand Up @@ -94,25 +96,31 @@ func newCmdProfile() *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
options.name = args[0]
clusterDomain := defaultClusterDomain
var k8sAPI *k8s.KubernetesAPI

err := options.validate()
if err != nil {
return err
}

k8sAPI, err := k8s.NewAPI(kubeconfigPath, kubeContext, impersonate, impersonateGroup, 0)
if err != nil {
return err
}

_, values, err := healthcheck.FetchCurrentConfiguration(cmd.Context(), k8sAPI, controlPlaneNamespace)
if err != nil {
return err
}

clusterDomain := values.GetGlobal().ClusterDomain
if clusterDomain == "" {
clusterDomain = defaultClusterDomain
// performs an online profile generation and access-check to k8s cluster to extract
// clusterDomain from linkerd configuration
// profile generation based on tap data requires access to k8s cluster
piyushsingariya marked this conversation as resolved.
Show resolved Hide resolved
if !options.ignoreCluster || options.tap != "" {
k8sAPI, err := k8s.NewAPI(kubeconfigPath, kubeContext, impersonate, impersonateGroup, 0)
if err != nil {
return err
}

_, values, err := healthcheck.FetchCurrentConfiguration(cmd.Context(), k8sAPI, controlPlaneNamespace)
if err != nil {
return err
}

clusterDomain = values.GetGlobal().ClusterDomain
if clusterDomain == "" {
clusterDomain = defaultClusterDomain
}
kleimkuhler marked this conversation as resolved.
Show resolved Hide resolved
}

if options.template {
Expand All @@ -137,6 +145,7 @@ func newCmdProfile() *cobra.Command {
cmd.PersistentFlags().UintVar(&options.tapRouteLimit, "tap-route-limit", options.tapRouteLimit, "Max number of routes to add to the profile")
cmd.PersistentFlags().StringVarP(&options.namespace, "namespace", "n", options.namespace, "Namespace of the service")
cmd.PersistentFlags().StringVar(&options.proto, "proto", options.proto, "Output a service profile based on the given Protobuf spec file")
cmd.PersistentFlags().BoolVar(&options.ignoreCluster, "ignore-cluster", options.ignoreCluster, "Output a service profile through offline generation")

return cmd
}