Skip to content
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
3 changes: 2 additions & 1 deletion frontend/src/API/apiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ class ApiService {
}): Promise<ReleaseHealthStatus[]> => {
if (!release) return [];

const ns = release.storageNamespace || release.namespace;
return await this.fetchWithSafeDefaults<ReleaseHealthStatus[]>({
url: `/api/helm/releases/${release.namespace}/${release.name}/resources?health=true`,
url: `/api/helm/releases/${ns}/${release.name}/resources?health=true`,
fallback: [],
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export default function InstalledPackageCard({
};

const onClick = async () => {
const { name, namespace } = release;
const { name, namespace, storageNamespace } = release;
const routingNamespace = storageNamespace || namespace;
await navigate(
`/${namespace}/${name}/installed/revision/${release.revision}`,
`/${routingNamespace}/${name}/installed/revision/${release.revision}`,
{
state: release,
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type Release = {
id: string;
name: string;
namespace: string;
storageNamespace?: string;
revision: number;
updated: string;
status: DeploymentStatus;
Expand Down
40 changes: 23 additions & 17 deletions pkg/dashboard/handlers/helmHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (h *HelmHandler) GetReleases(c *gin.Context) {

res := []*ReleaseElement{}
for _, r := range rels {
res = append(res, HReleaseToJSON(r.Orig))
res = append(res, HReleaseToJSON(r.Orig, r.StorageNamespace))
}

c.IndentedJSON(http.StatusOK, res)
Expand Down Expand Up @@ -157,7 +157,11 @@ func (h *HelmHandler) Resources(c *gin.Context) {
for _, obj := range res {
ns := obj.Namespace
if ns == "" {
ns = c.Param("ns")
if rel.Orig.Namespace != "" {
ns = rel.Orig.Namespace
} else {
ns = c.Param("ns")
}
}
kind := utils.QualifiedKind(obj.Kind, obj.APIVersion)
info, err := app.K8s.GetResourceInfo(kind, ns, obj.Name)
Expand Down Expand Up @@ -680,11 +684,12 @@ type RepoChartElement struct { // TODO: do we need it at all? there is existing
IsSuggestedRepo bool `json:"isSuggestedRepo"`
}

func HReleaseToJSON(o *release.Release) *ReleaseElement {
func HReleaseToJSON(o *release.Release, storageNamespace string) *ReleaseElement {
res := &ReleaseElement{
Name: o.Name,
Namespace: o.Namespace,
Revision: strconv.Itoa(o.Version),
Name: o.Name,
Namespace: o.Namespace,
StorageNamespace: storageNamespace,
Revision: strconv.Itoa(o.Version),
}
if o.Info != nil {
res.Updated = o.Info.LastDeployed
Expand All @@ -706,17 +711,18 @@ func HReleaseToJSON(o *release.Release) *ReleaseElement {
}

type ReleaseElement struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Revision string `json:"revision"`
Updated helmtime.Time `json:"updated"`
Status release.Status `json:"status"`
Chart string `json:"chart"`
ChartName string `json:"chartName"`
ChartVersion string `json:"chartVersion"`
AppVersion string `json:"app_version"`
Icon string `json:"icon"`
Description string `json:"description"`
Name string `json:"name"`
Namespace string `json:"namespace"`
StorageNamespace string `json:"storageNamespace,omitempty"`
Revision string `json:"revision"`
Updated helmtime.Time `json:"updated"`
Status release.Status `json:"status"`
Chart string `json:"chart"`
ChartName string `json:"chartName"`
ChartVersion string `json:"chartVersion"`
AppVersion string `json:"app_version"`
Icon string `json:"icon"`
Description string `json:"description"`
}

type RepositoryElement struct {
Expand Down
20 changes: 18 additions & 2 deletions pkg/dashboard/handlers/helmHandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestHReleaseToJSON(t *testing.T) {
},
}

res := HReleaseToJSON(rel)
res := HReleaseToJSON(rel, "")
if res == nil {
t.Fatal("expected non-nil ReleaseElement")
}
Expand All @@ -57,7 +57,7 @@ func TestHReleaseToJSON(t *testing.T) {
Version: 2,
}

res := HReleaseToJSON(rel)
res := HReleaseToJSON(rel, "")
if res == nil {
t.Fatal("expected non-nil ReleaseElement")
}
Expand All @@ -70,6 +70,22 @@ func TestHReleaseToJSON(t *testing.T) {
})
}

func TestHReleaseToJSON_StorageNamespace(t *testing.T) {
rel := &release.Release{
Name: "educates-contour",
Namespace: "projectcontour",
Version: 1,
}

res := HReleaseToJSON(rel, "educates")
if res.Namespace != "projectcontour" {
t.Errorf("expected release namespace projectcontour, got %q", res.Namespace)
}
if res.StorageNamespace != "educates" {
t.Errorf("expected storage namespace educates, got %q", res.StorageNamespace)
}
}

func TestHReleaseToHistElem(t *testing.T) {
now := helmtime.Time{Time: time.Now()}

Expand Down
1 change: 1 addition & 0 deletions pkg/dashboard/objects/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewApplication(settings *cli.EnvSettings, helmConfig HelmNSConfigGetter, na
Namespaces: namespaces,
Settings: settings,
HelmConfig: helmConfig,
K8s: k8s,
},
Repositories: &Repositories{
Settings: settings,
Expand Down
53 changes: 53 additions & 0 deletions pkg/dashboard/objects/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,23 @@ type cfgProxyObject struct {
}

func (p *cfgProxyObject) ToRESTConfig() (*rest.Config, error) {
if p == nil || p.Impl == nil {
return nil, errors.New("no REST client getter configured")
}
return p.Impl.ToRESTConfig()
}

func (p *cfgProxyObject) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
if p == nil || p.Impl == nil {
return nil, errors.New("no REST client getter configured")
}
return p.Impl.ToDiscoveryClient()
}

func (p *cfgProxyObject) ToRESTMapper() (meta.RESTMapper, error) {
if p == nil || p.Impl == nil {
return nil, errors.New("no REST client getter configured")
}
return p.Impl.ToRESTMapper()
}

Expand Down Expand Up @@ -98,6 +107,50 @@ func (k *K8s) GetNameSpaces() (res *corev1.NamespaceList, err error) {
return lst, nil
}

func (k *K8s) GetReleaseStorageNamespaces(driver string) (map[string]string, error) {
if k == nil || k.Factory == nil {
return nil, errors.New("k8s factory not initialized")
}

clientset, err := k.Factory.KubernetesClientSet()
if err != nil {
return nil, errors.Wrap(err, "failed to get KubernetesClientSet")
}

res := make(map[string]string)
opts := metav1.ListOptions{
LabelSelector: "owner=helm",
}

if driver == "configmap" || driver == "configmaps" {
cms, err := clientset.CoreV1().ConfigMaps("").List(context.Background(), opts)
if err != nil {
return nil, errors.Wrap(err, "failed to list release configmaps")
}
for _, cm := range cms.Items {
name := cm.Labels["name"]
version := cm.Labels["version"]
if name != "" && version != "" {
res[name+"#"+version] = cm.Namespace
}
}
} else {
secrets, err := clientset.CoreV1().Secrets("").List(context.Background(), opts)
if err != nil {
return nil, errors.Wrap(err, "failed to list release secrets")
}
for _, s := range secrets.Items {
name := s.Labels["name"]
version := s.Labels["version"]
if name != "" && version != "" {
res[name+"#"+version] = s.Namespace
}
}
}

return res, nil
}

func (k *K8s) DescribeResource(kind string, ns string, name string) (string, error) {
log.Debugf("Describing resource: %s %s in %s", kind, name, ns)
streams, _, out, errout := genericclioptions.NewTestIOStreams()
Expand Down
Loading
Loading