Browse Source

fix for kubeconfig

Alexander Belanger 5 năm trước cách đây
mục cha
commit
fd3977f6f1

+ 6 - 0
internal/forms/chart.go

@@ -84,3 +84,9 @@ type GetChartForm struct {
 	Name     string `json:"name" form:"required"`
 	Revision int    `json:"revision"`
 }
+
+// ListChartHistoryForm represents the accepted values for getting a single Helm chart
+type ListChartHistoryForm struct {
+	*ChartForm
+	Name string `json:"name" form:"required"`
+}

+ 9 - 0
internal/helm/agent.go

@@ -34,3 +34,12 @@ func (a *Agent) GetRelease(
 
 	return cmd.Run(name)
 }
+
+// GetReleaseHistory returns a list of charts for a specific release
+func (a *Agent) GetReleaseHistory(
+	name string,
+) ([]*release.Release, error) {
+	cmd := action.NewHistory(a.ActionConfig)
+
+	return cmd.Run(name)
+}

+ 35 - 0
internal/helm/agent_test.go

@@ -212,3 +212,38 @@ func TestGetReleases(t *testing.T) {
 		compareReleaseToStubs(t, []*release.Release{rel}, []releaseStub{tc.expRes})
 	}
 }
+
+var listReleaseHistoryTests = []listReleaseTest{
+	listReleaseTest{
+		name:      "simple history test",
+		namespace: "",
+		filter:    &helm.ListFilter{},
+		releases: []releaseStub{
+			releaseStub{"wordpress", "default", 2, "1.0.2", release.StatusDeployed},
+			releaseStub{"wordpress", "default", 1, "1.0.1", release.StatusSuperseded},
+		},
+		expRes: []releaseStub{
+			releaseStub{"wordpress", "default", 2, "1.0.2", release.StatusDeployed},
+			releaseStub{"wordpress", "default", 1, "1.0.1", release.StatusSuperseded},
+		},
+	},
+}
+
+func TestListReleaseHistory(t *testing.T) {
+	for _, tc := range listReleaseTests {
+		agent := newAgentFixture(t, tc.namespace)
+		makeReleases(t, agent, tc.releases)
+
+		// calling agent.ActionConfig.Releases.Create in makeReleases will automatically set the
+		// namespace, so we have to reset the namespace of the storage driver
+		agent.ActionConfig.Releases.Driver.(*driver.Memory).SetNamespace(tc.namespace)
+
+		releases, err := agent.GetReleaseHistory("wordpress")
+
+		if err != nil {
+			t.Errorf("%v", err)
+		}
+
+		compareReleaseToStubs(t, releases, tc.expRes)
+	}
+}

+ 4 - 3
internal/kubernetes/kubeconfig.go

@@ -36,15 +36,16 @@ func GetRestrictedClientConfigFromBytes(
 	// put allowed clusters in a map
 	aContextMap := createAllowedContextMap(allowedContexts)
 
-	// discover all allowed clusters
-	for name, context := range rawConf.Contexts {
+	context, ok := rawConf.Contexts[contextName]
+
+	if ok {
 		userName := context.AuthInfo
 		clusterName := context.Cluster
 		authInfo, userFound := rawConf.AuthInfos[userName]
 		cluster, clusterFound := rawConf.Clusters[clusterName]
 
 		// make sure the cluster is "allowed"
-		_, isAllowed := aContextMap[name]
+		_, isAllowed := aContextMap[contextName]
 
 		if userFound && clusterFound && isAllowed {
 			copyConf.Clusters[clusterName] = cluster