-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from teamcode-inc/feature/local-development
create cli tool to support local development (linked to #3)
- Loading branch information
Showing
20 changed files
with
949 additions
and
2 deletions.
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
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,4 @@ | ||
cli: | ||
GOARCH=amd64 GOOS=linux go build -o "orbitctl-linux" . | ||
GOARCH=amd64 GOOS=darwin go build -o "orbitctl-darwin" . | ||
GOARCH=amd64 GOOS=windows go build -o "orbitctl.exe" . |
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,37 @@ | ||
/* | ||
Copyright 2022 The TeamCode 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 main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"kubeorbit.io/pkg/cli/command" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "orbitctl", | ||
Long: `Orbitctl can forward traffic intended for a service in-clsuter to your local workload`, | ||
CompletionOptions: cobra.CompletionOptions{ | ||
DisableDefaultCmd: true, | ||
}, | ||
Example: "orbitctl forward --deployment depolyment-a --namespace ns-a --containerPort 8080 --localPort 8080", | ||
Version: "0.2.0", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(command.ForwardCommand()) | ||
rootCmd.AddCommand(command.UninstallCommand()) | ||
} | ||
|
||
func main() { | ||
cobra.CheckErr(rootCmd.Execute()) | ||
} |
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
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,59 @@ | ||
/* | ||
Copyright 2022 The TeamCode 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 ( | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
log "kubeorbit.io/pkg/cli/logger" | ||
) | ||
|
||
var kubeConfig *rest.Config | ||
var kubeClient *kubernetes.Clientset | ||
|
||
func init() { | ||
clusterConfig, err := newClusterConfig() | ||
kubeConfig = clusterConfig | ||
if err != nil { | ||
log.Fatalf("error loading kubeconfig: %v", err) | ||
} | ||
clientSet, err := kubernetes.NewForConfig(clusterConfig) | ||
if err != nil { | ||
log.Fatalf("error loading kubeconfig: %v", err) | ||
} | ||
kubeClient = clientSet | ||
} | ||
|
||
func KubeConfig() *rest.Config { | ||
return kubeConfig | ||
} | ||
|
||
func KubeClient() *kubernetes.Clientset { | ||
return kubeClient | ||
} | ||
|
||
func newClusterConfig() (*rest.Config, error) { | ||
var cfg *rest.Config | ||
var err error | ||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() | ||
cfg, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{}).ClientConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cfg.QPS = 100 | ||
cfg.Burst = 100 | ||
|
||
return cfg, nil | ||
} |
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,40 @@ | ||
/* | ||
Copyright 2022 The TeamCode 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 command | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"kubeorbit.io/pkg/cli/core" | ||
) | ||
|
||
func ForwardCommand() *cobra.Command { | ||
request := &core.ForwardRequest{} | ||
cmd := &cobra.Command{ | ||
Use: "forward", | ||
Long: `Forward a deployment to local`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := core.Forward(request) | ||
if err != nil { | ||
cmd.PrintErr(err) | ||
} | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&request.Namespace, "namespace", "n", "default", "Namespace for forwarding") | ||
cmd.Flags().StringVar(&request.DeploymentName, "deployment", "", "Deployment Name") | ||
cmd.Flags().IntVar(&request.LocalPort, "localPort", 0, "Local Port") | ||
cmd.Flags().IntVar(&request.ContainerPort, "containerPort", 0, "Container Port") | ||
cmd.MarkFlagRequired("deployment") | ||
cmd.MarkFlagRequired("localPort") | ||
cmd.MarkFlagRequired("containerPort") | ||
return cmd | ||
} |
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,35 @@ | ||
/* | ||
Copyright 2022 The TeamCode 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 command | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"kubeorbit.io/pkg/cli/core" | ||
) | ||
|
||
func UninstallCommand() *cobra.Command { | ||
request := &core.UninstallRequest{} | ||
cmd := &cobra.Command{ | ||
Use: "uninstall", | ||
Long: `Uninstall orbit agent and resources`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := core.Uninstall(request) | ||
if err != nil { | ||
cmd.PrintErr(err) | ||
} | ||
}, | ||
} | ||
cmd.Flags().StringVar(&request.Namespace, "namespace", "default", "Namespace for uninstall") | ||
cmd.Flags().StringVar(&request.DeploymentName, "deployment", "", "Deployment name for uninstall") | ||
return cmd | ||
} |
Oops, something went wrong.