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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ vendor
**/*.swp
**/charts/**/charts
package-lock.json
.vscode
42 changes: 28 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 All @@ -55,6 +57,10 @@ func (options *profileOptions) validate() error {
return errors.New("You must specify exactly one of --template or --open-api or --proto or --tap")
}

// service profile generation based on tap data requires access to k8s cluster
if options.ignoreCluster && options.tap != "" {
return errors.New("--ignore-cluster and --tap flags are mutually exclusive; SP generation based on tap data requires access-check to k8s cluster")
}
// a DNS-1035 label must consist of lower case alphanumeric characters or '-',
// start with an alphabetic character, and end with an alphanumeric character
if errs := validation.IsDNS1035Label(options.name); len(errs) != 0 {
Expand Down Expand Up @@ -94,25 +100,32 @@ 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 {
var err error
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
}

if cd := values.GetGlobal().ClusterDomain; cd != "" {
clusterDomain = cd
}
}

if options.template {
Expand All @@ -137,6 +150,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
}