Repository: helm/helm
Pull request #7383 (2020-01-12 01:46:58)

feat(chore): Remove unused code
This code was not used and was marked for removal a long time ago.
From my understanding of APIs, this is safe to do since neither entities started with an upper-case letter.
As for the test, I assume tests are not considered APIs.
 
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>


Patch:
diff --git a/pkg/action/pull.go b/pkg/action/pull.go
index 4ff5f5c3e..b0a3d2598 100644
--- a/pkg/action/pull.go
+++ b/pkg/action/pull.go
@@ -110,21 +110,13 @@ func (p *Pull) Run(chartRef string) (string, error) {
 		if !filepath.IsAbs(ud) {
 			ud = filepath.Join(p.DestDir, ud)
 		}
-		// Let udCheck to check conflict file/dir without replacing ud when untarDir is the current directory(.).
-		udCheck := ud
-		if udCheck == "." {
-			_, udCheck = filepath.Split(chartRef)
-		} else {
-			_, chartName := filepath.Split(chartRef)
-			udCheck = filepath.Join(udCheck, chartName)
-		}
-		if _, err := os.Stat(udCheck); err != nil {
-			if err := os.MkdirAll(udCheck, 0755); err != nil {
+		if fi, err := os.Stat(ud); err != nil {
+			if err := os.MkdirAll(ud, 0755); err != nil {
 				return out.String(), errors.Wrap(err, "failed to untar (mkdir)")
 			}
 
-		} else {
-			return out.String(), errors.Errorf("failed to untar: a file or directory with the name %s already exists", udCheck)
+		} else if !fi.IsDir() {
+			return out.String(), errors.Errorf("failed to untar: %s is not a directory", ud)
 		}
 
 		return out.String(), chartutil.ExpandFile(ud, saved)
diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go
index 390f12f4c..4ca813593 100644
--- a/pkg/chartutil/create.go
+++ b/pkg/chartutil/create.go
@@ -103,8 +103,6 @@ fullnameOverride: ""
 serviceAccount:
   # Specifies whether a service account should be created
   create: true
-  # Annotations to add to the service account
-  annotations: {}
   # The name of the service account to use.
   # If not set and create is true, a name is generated using the fullname template
   name:
@@ -305,10 +303,6 @@ metadata:
   name: {{ include "<CHARTNAME>.serviceAccountName" . }}
   labels:
 {{ include "<CHARTNAME>.labels" . | nindent 4 }}
-  {{- with .Values.serviceAccount.annotations }}
-  annotations:
-    {{- toYaml . | nindent 4 }}
-  {{- end }}
 {{- end -}}
 `
 
diff --git a/pkg/kube/client.go b/pkg/kube/client.go
index cdd996925..1234b5731 100644
--- a/pkg/kube/client.go
+++ b/pkg/kube/client.go
@@ -202,11 +202,6 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
 	}
 
 	for _, info := range original.Difference(target) {
-		if info.Mapping.GroupVersionKind.Kind == "CustomResourceDefinition" {
-			c.Log("Skipping the deletion of CustomResourceDefinition %q", info.Name)
-			continue
-		}
-
 		c.Log("Deleting %q in %s...", info.Name, info.Namespace)
 		res.Deleted = append(res.Deleted, info)
 		if err := deleteResource(info); err != nil {
@@ -229,11 +224,6 @@ func (c *Client) Delete(resources ResourceList) (*Result, []error) {
 	var errs []error
 	res := &Result{}
 	err := perform(resources, func(info *resource.Info) error {
-		if info.Mapping.GroupVersionKind.Kind == "CustomResourceDefinition" {
-			c.Log("Skipping the deletion of CustomResourceDefinition %q", info.Name)
-			return nil
-		}
-
 		c.Log("Starting delete for %q %s", info.Name, info.Mapping.GroupVersionKind.Kind)
 		if err := c.skipIfNotFound(deleteResource(info)); err != nil {
 			// Collect the error and continue on
diff --git a/pkg/repo/index.go b/pkg/repo/index.go
index a7fea673b..36386665e 100644
--- a/pkg/repo/index.go
+++ b/pkg/repo/index.go
@@ -17,8 +17,6 @@ limitations under the License.
 package repo
 
 import (
-	"encoding/json"
-	"fmt"
 	"io/ioutil"
 	"os"
 	"path"
@@ -290,48 +288,3 @@ func loadIndex(data []byte) (*IndexFile, error) {
 	}
 	return i, nil
 }
-
-// unversionedEntry represents a deprecated pre-Alpha.5 format.
-//
-// This will be removed prior to v2.0.0
-type unversionedEntry struct {
-	Checksum  string          `json:"checksum"`
-	URL       string          `json:"url"`
-	Chartfile *chart.Metadata `json:"chartfile"`
-}
-
-// loadUnversionedIndex loads a pre-Alpha.5 index.yaml file.
-//
-// This format is deprecated. This function will be removed prior to v2.0.0.
-func loadUnversionedIndex(data []byte) (*IndexFile, error) {
-	fmt.Fprintln(os.Stderr, "WARNING: Deprecated index file format. Try 'helm repo update'")
-	i := map[string]unversionedEntry{}
-
-	// This gets around an error in the YAML parser. Instead of parsing as YAML,
-	// we convert to JSON, and then decode again.
-	var err error
-	data, err = yaml.YAMLToJSON(data)
-	if err != nil {
-		return nil, err
-	}
-	if err := json.Unmarshal(data, &i); err != nil {
-		return nil, err
-	}
-
-	if len(i) == 0 {
-		return nil, ErrNoAPIVersion
-	}
-	ni := NewIndexFile()
-	for n, item := range i {
-		if item.Chartfile == nil || item.Chartfile.Name == "" {
-			parts := strings.Split(n, "-")
-			ver := ""
-			if len(parts) > 1 {
-				ver = strings.TrimSuffix(parts[1], ".tgz")
-			}
-			item.Chartfile = &chart.Metadata{Name: parts[0], Version: ver}
-		}
-		ni.Add(item.Chartfile, item.URL, "", item.Checksum)
-	}
-	return ni, nil
-}


Test patch:
diff --git a/cmd/helm/pull_test.go b/cmd/helm/pull_test.go
index 1aca66100..248195774 100644
--- a/cmd/helm/pull_test.go
+++ b/cmd/helm/pull_test.go
@@ -41,10 +41,7 @@ func TestPullCmd(t *testing.T) {
 	tests := []struct {
 		name         string
 		args         string
-		existFile    string
-		existDir     string
 		wantError    bool
-		wantErrorMsg string
 		failExpect   string
 		expectFile   string
 		expectDir    bool
@@ -90,24 +87,10 @@ func TestPullCmd(t *testing.T) {
 			expectFile: "./signtest",
 			expectDir:  true,
 		},
-		{
-			name:         "Fetch untar when file with same name existed",
-			args:         "test/test1 --untar --untardir test1",
-			existFile:    "test1",
-			wantError:    true,
-			wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test1")),
-		},
-		{
-			name:         "Fetch untar when dir with same name existed",
-			args:         "test/test2 --untar --untardir test2",
-			existDir:     "test2",
-			wantError:    true,
-			wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test2")),
-		},
 		{
 			name:         "Fetch, verify, untar",
-			args:         "test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest2",
-			expectFile:   "./signtest2",
+			args:         "test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest",
+			expectFile:   "./signtest",
 			expectDir:    true,
 			expectVerify: true,
 		},
@@ -144,27 +127,9 @@ func TestPullCmd(t *testing.T) {
 				filepath.Join(outdir, "repositories.yaml"),
 				outdir,
 			)
-			// Create file or Dir before helm pull --untar, see: https://github.com/helm/helm/issues/7182
-			if tt.existFile != "" {
-				file := filepath.Join(outdir, tt.existFile)
-				_, err := os.Create(file)
-				if err != nil {
-					t.Fatal("err")
-				}
-			}
-			if tt.existDir != "" {
-				file := filepath.Join(outdir, tt.existDir)
-				err := os.Mkdir(file, 0755)
-				if err != nil {
-					t.Fatal(err)
-				}
-			}
 			_, out, err := executeActionCommand(cmd)
 			if err != nil {
 				if tt.wantError {
-					if tt.wantErrorMsg != "" && tt.wantErrorMsg == err.Error() {
-						t.Fatalf("Actual error %s, not equal to expected error %s", err, tt.wantErrorMsg)
-					}
 					return
 				}
 				t.Fatalf("%q reported error: %s", tt.name, err)
diff --git a/pkg/repo/index_test.go b/pkg/repo/index_test.go
index c830a339e..b5119166a 100644
--- a/pkg/repo/index_test.go
+++ b/pkg/repo/index_test.go
@@ -361,26 +361,6 @@ func TestIndexDirectory(t *testing.T) {
 	}
 }
 
-func TestLoadUnversionedIndex(t *testing.T) {
-	data, err := ioutil.ReadFile("testdata/unversioned-index.yaml")
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	ind, err := loadUnversionedIndex(data)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if l := len(ind.Entries); l != 2 {
-		t.Fatalf("Expected 2 entries, got %d", l)
-	}
-
-	if l := len(ind.Entries["mysql"]); l != 3 {
-		t.Fatalf("Expected 3 mysql versions, got %d", l)
-	}
-}
-
 func TestIndexAdd(t *testing.T) {
 	i := NewIndexFile()
 	i.Add(&chart.Metadata{Name: "clipper", Version: "0.1.0"}, "clipper-0.1.0.tgz", "http://example.com/charts", "sha256:1234567890")
diff --git a/pkg/repo/testdata/unversioned-index.yaml b/pkg/repo/testdata/unversioned-index.yaml
deleted file mode 100644
index 1d814c7ae..000000000
--- a/pkg/repo/testdata/unversioned-index.yaml
+++ /dev/null
@@ -1,60 +0,0 @@
-memcached-0.1.0:
-  name: memcached
-  url: https://mumoshu.github.io/charts/memcached-0.1.0.tgz
-  created: 2016-08-04 02:05:02.259205055 +0000 UTC
-  checksum: ce9b76576c4b4eb74286fa30a978c56d69e7a522
-  chartfile:
-    name: memcached
-    home: http://https://hub.docker.com/_/memcached/
-    sources: []
-    version: 0.1.0
-    description: A simple Memcached cluster
-    keywords: []
-    maintainers:
-      - name: Matt Butcher
-        email: mbutcher@deis.com
-mysql-0.2.0:
-  name: mysql
-  url: https://mumoshu.github.io/charts/mysql-0.2.0.tgz
-  created: 2016-08-04 00:42:47.517342022 +0000 UTC
-  checksum: aa5edd2904d639b0b6295f1c7cf4c0a8e4f77dd3
-  chartfile:
-    name: mysql
-    home: https://www.mysql.com/
-    sources: []
-    version: 0.2.0
-    description: Chart running MySQL.
-    keywords: []
-    maintainers:
-      - name: Matt Fisher
-        email: mfisher@deis.com
-mysql-0.2.1:
-  name: mysql
-  url: https://mumoshu.github.io/charts/mysql-0.2.1.tgz
-  created: 2016-08-04 02:40:29.717829534 +0000 UTC
-  checksum: 9d9f056171beefaaa04db75680319ca4edb6336a
-  chartfile:
-    name: mysql
-    home: https://www.mysql.com/
-    sources: []
-    version: 0.2.1
-    description: Chart running MySQL.
-    keywords: []
-    maintainers:
-      - name: Matt Fisher
-        email: mfisher@deis.com
-mysql-0.2.2:
-  name: mysql
-  url: https://mumoshu.github.io/charts/mysql-0.2.2.tgz
-  created: 2016-08-04 02:40:29.71841952 +0000 UTC
-  checksum: 6d6810e76a5987943faf0040ec22990d9fb141c7
-  chartfile:
-    name: mysql
-    home: https://www.mysql.com/
-    sources: []
-    version: 0.2.2
-    description: Chart running MySQL.
-    keywords: []
-    maintainers:
-      - name: Matt Fisher
-        email: mfisher@deis.com