-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
- Loading branch information
Showing
8 changed files
with
474 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright Kurator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pixie | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"kurator.dev/kurator/cmd/kurator/app/install/pixie/vizier" | ||
"kurator.dev/kurator/pkg/generic" | ||
) | ||
|
||
func NewCmd(opts *generic.Options) *cobra.Command { | ||
pixieCmd := &cobra.Command{ | ||
Use: "pixie", | ||
Short: "Install pixie component", | ||
DisableFlagsInUseLine: true, | ||
FParseErrWhitelist: cobra.FParseErrWhitelist{ | ||
UnknownFlags: true, | ||
}, | ||
} | ||
|
||
pixieCmd.AddCommand(vizier.NewCmd(opts)) | ||
|
||
return pixieCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright Kurator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vizier | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
"kurator.dev/kurator/pkg/generic" | ||
plugin "kurator.dev/kurator/pkg/plugin/pixie/vizier" | ||
) | ||
|
||
const ( | ||
communityCloudAddr = "withpixie.ai:443" | ||
pxNamespace = "px" | ||
) | ||
|
||
func NewCmd(opts *generic.Options) *cobra.Command { | ||
pluginArgs := plugin.InstallArgs{} | ||
vizierCmd := &cobra.Command{ | ||
Use: "vizier", | ||
Short: "Install vizier component", | ||
RunE: func(c *cobra.Command, args []string) error { | ||
plugin, err := plugin.NewPlugin(opts, &pluginArgs) | ||
if err != nil { | ||
logrus.Errorf("pixie vizier init error: %v", err) | ||
return fmt.Errorf("pixie vizier init error: %v", err) | ||
} | ||
|
||
if err := plugin.Execute(args, nil); err != nil { | ||
logrus.Errorf("pixie vizier execute error: %v", err) | ||
return fmt.Errorf("pixie vizier execute error: %v", err) | ||
} | ||
logrus.Info("pixie vizier install completed.") | ||
return nil | ||
}, | ||
} | ||
|
||
vizierCmd.PersistentFlags().StringVar(&pluginArgs.PxNamespace, "px-namespace", pxNamespace, "The namespace use to install vizier.") | ||
vizierCmd.PersistentFlags().StringVar(&pluginArgs.CloudAddress, "cloud-addr", communityCloudAddr, "The address of the Pixie cloud instance that the vizier should be connected to.") | ||
vizierCmd.PersistentFlags().StringVar(&pluginArgs.DeployKey, "deploy-key", "", "The deploy key is used to link the deployed vizier to a specific user/project.") | ||
|
||
return vizierCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
Copyright Kurator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/client-go/discovery" | ||
"k8s.io/client-go/discovery/cached/memory" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/restmapper" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
// RESTClientGetter defines the values of a helm REST client. | ||
type RESTClientGetter struct { | ||
restConfig *rest.Config | ||
} | ||
|
||
// NewRESTClientGetter returns a RESTClientGetter using the provided 'restConfig'. | ||
// | ||
// source: https://github.com/helm/helm/issues/6910#issuecomment-601277026 | ||
func NewRESTClientGetter(restConfig *rest.Config) *RESTClientGetter { | ||
return &RESTClientGetter{ | ||
restConfig: restConfig, | ||
} | ||
} | ||
|
||
// ToRESTConfig returns a REST config build from a given kubeconfig | ||
func (c *RESTClientGetter) ToRESTConfig() (*rest.Config, error) { | ||
if c.restConfig != nil { | ||
return c.restConfig, nil | ||
} | ||
|
||
return nil, fmt.Errorf("restconfig can not be empty") | ||
} | ||
|
||
// ToDiscoveryClient returns a CachedDiscoveryInterface that can be used as a discovery client. | ||
func (c *RESTClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) { | ||
config, err := c.ToRESTConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// The more API groups exist, the more discovery requests need to be made. | ||
// Given 25 API groups with about one version each, discovery needs to make 50 requests. | ||
// This setting is only used for discovery. | ||
config.Burst = 100 | ||
|
||
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return memory.NewMemCacheClient(discoveryClient), nil | ||
} | ||
|
||
func (c *RESTClientGetter) ToRESTMapper() (meta.RESTMapper, error) { | ||
discoveryClient, err := c.ToDiscoveryClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mapper := restmapper.NewDeferredDiscoveryRESTMapper(discoveryClient) | ||
expander := restmapper.NewShortcutExpander(mapper, discoveryClient) | ||
return expander, nil | ||
} | ||
|
||
func (c *RESTClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig { | ||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() | ||
// use the standard defaults for this client command | ||
// DEPRECATED: remove and replace with something more accurate | ||
loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig | ||
|
||
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults} | ||
|
||
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.