Skip to content

Commit 7ba6715

Browse files
authored
Remove multi index flag (#624)
* Remove multi-index flag * Add comment explaining why index is being modified * Fix info example indentation * Update install help message * Make install help message more consistent * Remove multi index flag from ci test * Remove comment * Move custom index example down
1 parent 1096a4d commit 7ba6715

21 files changed

+82
-165
lines changed

cmd/krew/cmd/index.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ var (
3535

3636
// indexCmd represents the index command
3737
var indexCmd = &cobra.Command{
38-
Use: "index",
39-
Short: "Manage custom plugin indexes",
40-
Long: "Manage which repositories are used to discover and install plugins from.",
41-
Args: cobra.NoArgs,
42-
Hidden: true, // TODO(chriskim06) remove this once multi-index is enabled
38+
Use: "index",
39+
Short: "Manage custom plugin indexes",
40+
Long: "Manage which repositories are used to discover and install plugins from.",
41+
Args: cobra.NoArgs,
4342
}
4443

4544
var indexListCmd = &cobra.Command{
@@ -142,8 +141,5 @@ func init() {
142141
indexCmd.AddCommand(indexAddCmd)
143142
indexCmd.AddCommand(indexListCmd)
144143
indexCmd.AddCommand(indexDeleteCmd)
145-
146-
if _, ok := os.LookupEnv(constants.EnableMultiIndexSwitch); ok {
147-
rootCmd.AddCommand(indexCmd)
148-
}
144+
rootCmd.AddCommand(indexCmd)
149145
}

cmd/krew/cmd/info.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ import (
2828
"sigs.k8s.io/krew/internal/index/indexscanner"
2929
"sigs.k8s.io/krew/internal/installation"
3030
"sigs.k8s.io/krew/internal/pathutil"
31-
"sigs.k8s.io/krew/pkg/constants"
3231
"sigs.k8s.io/krew/pkg/index"
3332
)
3433

3534
// infoCmd represents the info command
3635
var infoCmd = &cobra.Command{
37-
Use: "info",
38-
Short: "Show information about an available plugin",
39-
Long: `Show detailed information about an available plugin.`,
40-
Example: "kubectl krew info PLUGIN",
36+
Use: "info",
37+
Short: "Show information about an available plugin",
38+
Long: `Show detailed information about an available plugin.`,
39+
Example: ` kubectl krew info PLUGIN
40+
kubectl krew info INDEX/PLUGIN`,
4141
RunE: func(cmd *cobra.Command, args []string) error {
4242
index, plugin := pathutil.CanonicalPluginName(args[0])
4343

@@ -95,10 +95,5 @@ func indent(s string) string {
9595
}
9696

9797
func init() {
98-
if os.Getenv(constants.EnableMultiIndexSwitch) != "" {
99-
// TODO(ahmetb) move back into Example field above (with 2-space indent) once feature gate is removed.
100-
infoCmd.Example += "\n kubectl krew info INDEX/PLUGIN"
101-
}
102-
10398
rootCmd.AddCommand(infoCmd)
10499
}

cmd/krew/cmd/install.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,19 @@ func init() {
5151
Long: `Install one or multiple kubectl plugins.
5252
5353
Examples:
54-
To install one or multiple plugins, run:
54+
To install one or multiple plugins from the default index, run:
5555
kubectl krew install NAME [NAME...]
5656
5757
To install plugins from a newline-delimited file, run:
5858
kubectl krew install < file.txt
5959
60+
To install one or multiple plugins from a custom index, run:
61+
kubectl krew install INDEX/NAME [INDEX/NAME...]
62+
6063
(For developers) To provide a custom plugin manifest, use the --manifest or
6164
--manifest-url arguments. Similarly, instead of downloading files from a URL,
6265
you can specify a local --archive file:
63-
kubectl krew install --manifest=FILE [--archive=FILE]
66+
kubectl krew install --manifest=FILE [--archive=FILE]
6467
6568
Remarks:
6669
If a plugin is already installed, it will be skipped.

cmd/krew/cmd/root.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,13 @@ func preRun(cmd *cobra.Command, _ []string) error {
149149
return errors.New("krew home outdated")
150150
}
151151

152-
if _, ok := os.LookupEnv(constants.EnableMultiIndexSwitch); ok {
153-
isMigrated, err := indexmigration.Done(paths)
154-
if err != nil {
155-
return errors.Wrap(err, "failed to check if index migration is complete")
156-
}
157-
if !isMigrated {
158-
if err := indexmigration.Migrate(paths); err != nil {
159-
return errors.Wrap(err, "index migration failed")
160-
}
152+
isMigrated, err = indexmigration.Done(paths)
153+
if err != nil {
154+
return errors.Wrap(err, "failed to check if index migration is complete")
155+
}
156+
if !isMigrated {
157+
if err := indexmigration.Migrate(paths); err != nil {
158+
return errors.Wrap(err, "index migration failed")
161159
}
162160
}
163161

cmd/krew/cmd/update.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ func loadPlugins(indexes []indexoperations.Index) []pluginEntry {
121121
}
122122

123123
func ensureIndexes(_ *cobra.Command, _ []string) error {
124-
if os.Getenv(constants.EnableMultiIndexSwitch) != "" {
125-
klog.V(3).Infof("Will check if there are any indexes added.")
126-
if err := ensureDefaultIndexIfNoneExist(); err != nil {
127-
return err
128-
}
124+
klog.V(3).Infof("Will check if there are any indexes added.")
125+
if err := ensureDefaultIndexIfNoneExist(); err != nil {
126+
return err
129127
}
130128
return ensureIndexesUpdated()
131129
}
@@ -173,7 +171,7 @@ func ensureIndexesUpdated() error {
173171
continue
174172
}
175173

176-
if os.Getenv(constants.EnableMultiIndexSwitch) == "" || isDefaultIndex(idx.Name) {
174+
if isDefaultIndex(idx.Name) {
177175
fmt.Fprintln(os.Stderr, "Updated the local copy of plugin index.")
178176
} else {
179177
fmt.Fprintf(os.Stderr, "Updated the local copy of plugin index %q.\n", idx.Name)

hack/verify-index-migration.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ run_krew() {
6565
krew_root="${1}"
6666
shift
6767

68-
# TODO(chriskim06): remove multi index flag once feature gate is removed
6968
env KREW_ROOT="${krew_root}" \
7069
PATH="${krew_root}/bin:$PATH" \
71-
X_KREW_ENABLE_MULTI_INDEX=1 \
7270
kubectl krew "$@"
7371
}
7472

integration_test/index_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestKrewIndexAdd(t *testing.T) {
2929
test, cleanup := NewTest(t)
3030
defer cleanup()
3131

32-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
32+
test.WithDefaultIndex()
3333
if _, err := test.Krew("index", "add").Run(); err == nil {
3434
t.Fatal("expected index add with no args to fail")
3535
}
@@ -51,7 +51,7 @@ func TestKrewIndexAddUnsafe(t *testing.T) {
5151
skipShort(t)
5252
test, cleanup := NewTest(t)
5353
defer cleanup()
54-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
54+
test.WithDefaultIndex()
5555

5656
cases := []string{"a/b", `a\b`, "../a", `..\a`}
5757
expected := "invalid index name"
@@ -72,7 +72,7 @@ func TestKrewIndexAddShowsSecurityWarning(t *testing.T) {
7272
test, cleanup := NewTest(t)
7373
defer cleanup()
7474

75-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
75+
test.WithDefaultIndex()
7676
out := string(test.Krew("index", "add", "foo", test.TempDir().Path("index/"+constants.DefaultIndexName)).RunOrFailOutput())
7777
if !strings.Contains(out, "WARNING: You have added a new index") {
7878
t.Errorf("expected output to contain warning when adding custom index: %v", out)
@@ -85,7 +85,7 @@ func TestKrewIndexList(t *testing.T) {
8585
test, cleanup := NewTest(t)
8686
defer cleanup()
8787

88-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
88+
test.WithDefaultIndex()
8989
out := test.Krew("index", "list").RunOrFailOutput()
9090
if indexes := lines(out); len(indexes) < 2 {
9191
// the first line is the header
@@ -106,7 +106,7 @@ func TestKrewIndexList_NoIndexes(t *testing.T) {
106106
test, cleanup := NewTest(t)
107107
defer cleanup()
108108

109-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
109+
test.WithDefaultIndex()
110110
index := test.TempDir().Path("index")
111111
if err := os.RemoveAll(index); err != nil {
112112
t.Fatalf("error removing default index: %v", err)
@@ -122,7 +122,6 @@ func TestKrewIndexList_NoIndexes(t *testing.T) {
122122
func TestKrewIndexRemove_nonExisting(t *testing.T) {
123123
skipShort(t)
124124
test, cleanup := NewTest(t)
125-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
126125
defer cleanup()
127126

128127
_, err := test.Krew("index", "remove", "non-existing").Run()
@@ -134,7 +133,7 @@ func TestKrewIndexRemove_nonExisting(t *testing.T) {
134133
func TestKrewIndexRemove_ok(t *testing.T) {
135134
skipShort(t)
136135
test, cleanup := NewTest(t)
137-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex().WithCustomIndexFromDefault("foo")
136+
test.WithDefaultIndex().WithCustomIndexFromDefault("foo")
138137
defer cleanup()
139138

140139
test.Krew("index", "remove", "foo").RunOrFail()
@@ -143,7 +142,7 @@ func TestKrewIndexRemove_ok(t *testing.T) {
143142
func TestKrewIndexRemove_unsafe(t *testing.T) {
144143
skipShort(t)
145144
test, cleanup := NewTest(t)
146-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
145+
test.WithDefaultIndex()
147146
defer cleanup()
148147

149148
expected := "invalid index name"
@@ -161,7 +160,7 @@ func TestKrewIndexRemove_unsafe(t *testing.T) {
161160
func TestKrewIndexRemoveFailsWhenPluginsInstalled(t *testing.T) {
162161
skipShort(t)
163162
test, cleanup := NewTest(t)
164-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
163+
test.WithDefaultIndex()
165164
defer cleanup()
166165

167166
test.Krew("install", validPlugin).RunOrFailOutput()
@@ -176,7 +175,6 @@ func TestKrewIndexRemoveFailsWhenPluginsInstalled(t *testing.T) {
176175
func TestKrewIndexRemoveForce_nonExisting(t *testing.T) {
177176
skipShort(t)
178177
test, cleanup := NewTest(t)
179-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
180178
defer cleanup()
181179

182180
// --force returns success for non-existing indexes
@@ -186,7 +184,6 @@ func TestKrewIndexRemoveForce_nonExisting(t *testing.T) {
186184
func TestKrewDefaultIndex_notAutomaticallyAdded(t *testing.T) {
187185
skipShort(t)
188186
test, cleanup := NewTest(t)
189-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
190187
defer cleanup()
191188

192189
test.Krew("help").RunOrFail()
@@ -203,7 +200,6 @@ func TestKrewDefaultIndex_notAutomaticallyAdded(t *testing.T) {
203200
func TestKrewDefaultIndex_AutoAddedOnInstall(t *testing.T) {
204201
skipShort(t)
205202
test, cleanup := NewTest(t)
206-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
207203
defer cleanup()
208204

209205
test.Krew("install", validPlugin).RunOrFail()
@@ -213,7 +209,6 @@ func TestKrewDefaultIndex_AutoAddedOnInstall(t *testing.T) {
213209
func TestKrewDefaultIndex_AutoAddedOnUpdate(t *testing.T) {
214210
skipShort(t)
215211
test, cleanup := NewTest(t)
216-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
217212
defer cleanup()
218213

219214
test.Krew("update").RunOrFail()
@@ -223,7 +218,6 @@ func TestKrewDefaultIndex_AutoAddedOnUpdate(t *testing.T) {
223218
func TestKrewDefaultIndex_AutoAddedOnUpgrade(t *testing.T) {
224219
skipShort(t)
225220
test, cleanup := NewTest(t)
226-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
227221
defer cleanup()
228222

229223
test.Krew("upgrade").RunOrFail()

integration_test/info_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package integrationtest
1717
import (
1818
"strings"
1919
"testing"
20-
21-
"sigs.k8s.io/krew/pkg/constants"
2220
)
2321

2422
func TestKrewInfo(t *testing.T) {
@@ -53,7 +51,7 @@ func TestKrewInfoCustomIndex(t *testing.T) {
5351
test, cleanup := NewTest(t)
5452
defer cleanup()
5553

56-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex().WithCustomIndexFromDefault("foo")
54+
test = test.WithDefaultIndex().WithCustomIndexFromDefault("foo")
5755
test.Krew("install", "foo/"+validPlugin).RunOrFail()
5856

5957
out := string(test.Krew("info", "foo/"+validPlugin).RunOrFailOutput())

integration_test/install_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestKrewInstallUnsafe(t *testing.T) {
6262
skipShort(t)
6363
test, cleanup := NewTest(t)
6464
defer cleanup()
65-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
65+
test.WithDefaultIndex()
6666

6767
cases := []string{
6868
`../index/` + validPlugin,
@@ -138,7 +138,7 @@ func TestKrewInstall_CustomIndex(t *testing.T) {
138138
test, cleanup := NewTest(t)
139139
defer cleanup()
140140

141-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex().WithCustomIndexFromDefault("foo")
141+
test.WithDefaultIndex().WithCustomIndexFromDefault("foo")
142142
test.Krew("install", "foo/"+validPlugin).RunOrFail()
143143
test.AssertExecutableInPATH("kubectl-" + validPlugin)
144144
test.AssertPluginFromIndex(validPlugin, "foo")
@@ -155,7 +155,7 @@ func TestKrewInstallNoSecurityWarningForCustomIndex(t *testing.T) {
155155
test, cleanup := NewTest(t)
156156
defer cleanup()
157157

158-
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex().WithCustomIndexFromDefault("foo")
158+
test.WithDefaultIndex().WithCustomIndexFromDefault("foo")
159159
out := string(test.Krew("install", "foo/"+validPlugin).RunOrFailOutput())
160160
if strings.Contains(out, "Run them at your own risk") {
161161
t.Errorf("expected install of custom plugin to not show security warning: %v", out)

integration_test/list_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package integrationtest
1616

1717
import (
18-
"os"
1918
"sort"
2019
"strings"
2120
"testing"
@@ -36,7 +35,7 @@ func TestKrewList(t *testing.T) {
3635
test, cleanup := NewTest(t)
3736
defer cleanup()
3837

39-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex().WithCustomIndexFromDefault("foo")
38+
test = test.WithDefaultIndex().WithCustomIndexFromDefault("foo")
4039
initialList := test.Krew("list").RunOrFailOutput()
4140
initialOut := []byte{'\n'}
4241

@@ -66,9 +65,7 @@ func TestKrewListSorted(t *testing.T) {
6665
test, cleanup := NewTest(t)
6766
defer cleanup()
6867

69-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
70-
os.Setenv(constants.EnableMultiIndexSwitch, "1")
71-
defer os.Unsetenv(constants.EnableMultiIndexSwitch)
68+
test = test.WithDefaultIndex()
7269

7370
paths := environment.NewPaths(test.Root())
7471
ps, err := indexscanner.LoadPluginListFromFS(paths.IndexPluginsPath(constants.DefaultIndexName))

0 commit comments

Comments
 (0)