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

Remove unused code #422

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
46 changes: 4 additions & 42 deletions pkg/cobras/templates/helpers.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
package templates

import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

jxCore "github.com/jenkins-x/jx-api/v4/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned"
"github.com/jenkins-x/jx-helpers/v3/pkg/extensions"
"github.com/jenkins-x/jx-helpers/v3/pkg/kube/jxclient"
"github.com/jenkins-x/jx-logging/v3/pkg/log"

"github.com/spf13/cobra"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
)

type Options struct {
ManagedPluginsEnabled bool
JXClient versioned.Interface
Namespace string
}

// GetPluginCommandGroups returns the plugin groups
func (o *Options) GetPluginCommandGroups(verifier extensions.PathVerifier, localPlugins []jxCore.Plugin) (PluginCommandGroups, error) {
func GetPluginCommandGroups(verifier extensions.PathVerifier, localPlugins []jxCore.Plugin) (PluginCommandGroups, error) {

otherCommands := PluginCommandGroup{
Message: "Other Commands",
}
groups := make(map[string]PluginCommandGroup, 0)

o.addPlugins(localPlugins, &otherCommands, groups)

err := o.addManagedPlugins(&otherCommands, groups)
if err != nil {
return nil, fmt.Errorf("failed to add managed plugins: %w", err)
}
addPlugins(localPlugins, &otherCommands, groups)

pathCommands := PluginCommandGroup{
Message: "Locally Available Commands:",
Expand Down Expand Up @@ -96,27 +78,7 @@ func (o *Options) GetPluginCommandGroups(verifier extensions.PathVerifier, local
return pcgs, nil
}

func (o *Options) addManagedPlugins(otherCommands *PluginCommandGroup, groups map[string]PluginCommandGroup) error {
// Managed plugins
var err error
if o.ManagedPluginsEnabled {
o.JXClient, o.Namespace, err = jxclient.LazyCreateJXClientAndNamespace(o.JXClient, o.Namespace)
if err != nil {
return fmt.Errorf("failed to create jx client: %w", err)
}
pluginList, err := o.JXClient.JenkinsV1().Plugins(o.Namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil && apierrors.IsNotFound(err) {
err = nil
}
if err != nil {
log.Logger().Debugf("failed to find Plugin CRDs in kubernetes namespace %s due to: %s", o.Namespace, err.Error())
}
o.addPlugins(pluginList.Items, otherCommands, groups)
}
return nil
}

func (o *Options) addPlugins(pluginSlice []jxCore.Plugin, otherCommands *PluginCommandGroup, groups map[string]PluginCommandGroup) {
func addPlugins(pluginSlice []jxCore.Plugin, otherCommands *PluginCommandGroup, groups map[string]PluginCommandGroup) {
for _, plugin := range pluginSlice {
pluginCommand := &PluginCommand{
PluginSpec: plugin.Spec,
Expand All @@ -139,7 +101,7 @@ func (o *Options) addPlugins(pluginSlice []jxCore.Plugin, otherCommands *PluginC
}

// ActsAsRootCommand act as if the given set of plugins is a single root command
func ActsAsRootCommand(cmd *cobra.Command, filters []string, getPluginCommandGroups func() (PluginCommandGroups, bool), groups ...CommandGroup) FlagExposer {
func ActsAsRootCommand(cmd *cobra.Command, filters []string, getPluginCommandGroups func() PluginCommandGroups, groups ...CommandGroup) FlagExposer {
if cmd == nil {
panic("nil root command")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cobras/templates/templater.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func UseOptionsTemplates(cmd *cobra.Command) {
type templater struct {
UsageTemplate string
HelpTemplate string
GetPluginCommandGroups func() (PluginCommandGroups, bool)
GetPluginCommandGroups func() PluginCommandGroups
RootCmd *cobra.Command
CommandGroups
Filtered []string
Expand Down Expand Up @@ -154,7 +154,7 @@ func (t *templater) cmdGroupsString(c *cobra.Command) string {
}
}
}
pluginCommandGroups, _ := t.GetPluginCommandGroups()
pluginCommandGroups := t.GetPluginCommandGroups()
if c == t.RootCmd {
for _, cmdGroup := range pluginCommandGroups {
for _, cmd := range cmdGroup.Commands {
Expand Down
5 changes: 2 additions & 3 deletions pkg/kube/activities/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
jxfake "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned/fake"
typev1 "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned/typed/jenkins.io/v1"
"github.com/jenkins-x/jx-helpers/v3/pkg/gitclient/giturl"
"github.com/jenkins-x/jx-helpers/v3/pkg/kube"
"github.com/jenkins-x/jx-helpers/v3/pkg/kube/activities"
appsv1 "k8s.io/api/apps/v1"
k8s_v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -81,15 +80,15 @@ func TestCreateOrUpdateActivities(t *testing.T) {

ingressConfig := &k8s_v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: kube.ConfigMapIngressConfig,
Name: "ingress-config",
},
Data: map[string]string{"key1": "value1", "domain": "test-domain", "config.yml": ""},
}

mockKubeClient.CoreV1().ConfigMaps(nsObj.Namespace).Create(context.TODO(), ingressConfig, metav1.CreateOptions{})
mockTektonDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: kube.DeploymentTektonController,
Name: "tekton-pipelines-controller",
},
}
mockKubeClient.AppsV1().Deployments(nsObj.Namespace).Create(context.TODO(), mockTektonDeployment, metav1.CreateOptions{})
Expand Down
Loading