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

Sidepanel update #540

Closed
wants to merge 16 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
import { Validators } from '@angular/forms';

import { metricEntityType } from '../../../../cloud-foundry/src/cf-entity-types';
import { IFavoriteMetadata } from '../../../../store/src/types/user-favorites.types';
import {
StratosBaseCatalogueEntity,
StratosCatalogueEndpointEntity,
StratosCatalogueEntity,
} from '../../core/entity-catalogue/entity-catalogue-entity';
import { StratosEndpointExtensionDefinition } from '../../core/entity-catalogue/entity-catalogue.types';
import { EndpointAuthTypeConfig, EndpointType } from '../../core/extension/extension-types';
import { KubernetesAWSAuthFormComponent } from './auth-forms/kubernetes-aws-auth-form/kubernetes-aws-auth-form.component';
import {
KubernetesCertsAuthFormComponent,
} from './auth-forms/kubernetes-certs-auth-form/kubernetes-certs-auth-form.component';
import {
KubernetesConfigAuthFormComponent,
} from './auth-forms/kubernetes-config-auth-form/kubernetes-config-auth-form.component';
import { KubernetesGKEAuthFormComponent } from './auth-forms/kubernetes-gke-auth-form/kubernetes-gke-auth-form.component';
import { KubernetesEndpointPreviewComponent } from './kubernetes-endpoint-preview/kubernetes-endpoint-preview.component';
import {
KUBERNETES_ENDPOINT_TYPE,
kubernetesAppsEntityType,
kubernetesDashboardEntityType,
kubernetesDeploymentsEntityType,
kubernetesEntityFactory,
kubernetesNamespacesEntityType,
kubernetesNodesEntityType,
kubernetesPodsEntityType,
kubernetesServicesEntityType,
kubernetesStatefulSetsEntityType,
} from './kubernetes-entity-factory';
import {
KubernetesApp,
KubernetesDeployment,
KubernetesNamespace,
KubernetesNode,
KubernetesPod,
KubernetesStatefulSet,
KubeService,
} from './store/kube.types';

const enum KubeEndpointAuthTypes {
CERT_AUTH = 'kube-cert-auth',
CONFIG = 'kubeconfig',
CONFIG_AZ = 'kubeconfig-az',
AWS_IAM = 'aws-iam',
GKE = 'gke-auth'
}

const kubeAuthTypeMap: { [type: string]: EndpointAuthTypeConfig } = {
[KubeEndpointAuthTypes.CERT_AUTH]: {
value: KubeEndpointAuthTypes.CERT_AUTH,
name: 'Kubernetes Cert Auth',
form: {
cert: ['', Validators.required],
certKey: ['', Validators.required],
},
types: new Array<EndpointType>(),
component: KubernetesCertsAuthFormComponent
},
[KubeEndpointAuthTypes.CONFIG]: {
value: KubeEndpointAuthTypes.CONFIG,
name: 'CAASP (OIDC)',
form: {
kubeconfig: ['', Validators.required],
},
types: new Array<EndpointType>(),
component: KubernetesConfigAuthFormComponent
},
[KubeEndpointAuthTypes.CONFIG_AZ]: {
value: KubeEndpointAuthTypes.CONFIG_AZ,
name: 'Azure AKS',
form: {
kubeconfig: ['', Validators.required],
},
types: new Array<EndpointType>(),
component: KubernetesConfigAuthFormComponent
},
[KubeEndpointAuthTypes.AWS_IAM]: {
value: KubeEndpointAuthTypes.AWS_IAM,
name: 'AWS IAM (EKS)',
form: {
cluster: ['', Validators.required],
access_key: ['', Validators.required],
secret_key: ['', Validators.required],
},
types: new Array<EndpointType>(),
component: KubernetesAWSAuthFormComponent
},
[KubeEndpointAuthTypes.GKE]: {
value: KubeEndpointAuthTypes.GKE,
name: 'GKE',
form: {
gkeconfig: ['', Validators.required],
},
types: new Array<EndpointType>(),
component: KubernetesGKEAuthFormComponent,
help: '/core/assets/custom/help/en/connecting_gke.md'
}
};

export function generateKubernetesEntities(): StratosBaseCatalogueEntity[] {
const endpointDefinition: StratosEndpointExtensionDefinition = {
type: KUBERNETES_ENDPOINT_TYPE,
label: 'Kubernetes',
labelPlural: 'Kubernetes',
icon: 'kubernetes',
iconFont: 'stratos-icons',
logoUrl: '/core/assets/custom/kubernetes.svg',
urlValidation: undefined,
authTypes: [kubeAuthTypeMap[KubeEndpointAuthTypes.CERT_AUTH]],
renderPriority: 4,
subTypes: [{
type: 'caasp',
label: 'SUSE CaaS Platform',
authTypes: [kubeAuthTypeMap[KubeEndpointAuthTypes.CONFIG]],
logoUrl: '/core/assets/custom/caasp.png',
renderPriority: 5
}, {
type: 'aks',
label: 'Azure AKS',
authTypes: [kubeAuthTypeMap[KubeEndpointAuthTypes.CONFIG_AZ]],
logoUrl: '/core/assets/custom/aks.svg',
renderPriority: 6
}, {
type: 'eks',
label: 'Amazon EKS',
authTypes: [kubeAuthTypeMap[KubeEndpointAuthTypes.AWS_IAM]],
logoUrl: '/core/assets/custom/eks.svg',
renderPriority: 6
}, {
type: 'gke',
label: 'Google Kubernetes Engine',
authTypes: [kubeAuthTypeMap[KubeEndpointAuthTypes.GKE]],
logoUrl: '/core/assets/custom/gke.svg',
renderPriority: 6
}],
};
return [
generateEndpointEntity(endpointDefinition),
generateAppEntity(endpointDefinition),
generateStatefulSetsEntity(endpointDefinition),
generatePodsEntity(endpointDefinition),
generateDeploymentsEntity(endpointDefinition),
generateNodesEntity(endpointDefinition),
generateNamespacesEntity(endpointDefinition),
generateServicesEntity(endpointDefinition),
generateDashboardEntity(endpointDefinition),
generateMetricEntity(endpointDefinition)
];
}

function generateEndpointEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
return new StratosCatalogueEndpointEntity(
endpointDefinition,
metadata => `/kubernetes/${metadata.guid}`,
() => KubernetesEndpointPreviewComponent,
);
}

function generateAppEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesAppsEntityType,
schema: kubernetesEntityFactory(kubernetesAppsEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubernetesApp>(definition);
}

function generateStatefulSetsEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesStatefulSetsEntityType,
schema: kubernetesEntityFactory(kubernetesStatefulSetsEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubernetesStatefulSet>(definition);
}

function generatePodsEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesPodsEntityType,
schema: kubernetesEntityFactory(kubernetesPodsEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubernetesPod>(definition);
}

function generateDeploymentsEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesDeploymentsEntityType,
schema: kubernetesEntityFactory(kubernetesDeploymentsEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubernetesDeployment>(definition);
}

function generateNodesEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesNodesEntityType,
schema: kubernetesEntityFactory(kubernetesNodesEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubernetesNode>(definition);
}

function generateNamespacesEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesNamespacesEntityType,
schema: kubernetesEntityFactory(kubernetesNamespacesEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubernetesNamespace>(definition);
}

function generateServicesEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesServicesEntityType,
schema: kubernetesEntityFactory(kubernetesServicesEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, KubeService>(definition);
}

function generateDashboardEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: kubernetesDashboardEntityType,
schema: kubernetesEntityFactory(kubernetesDashboardEntityType),
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata>(definition);
}

function generateMetricEntity(endpointDefinition: StratosEndpointExtensionDefinition) {
const definition = {
type: metricEntityType,
schema: kubernetesEntityFactory(metricEntityType),
label: 'Kubernetes Metric',
labelPlural: 'Kubernetes Metrics',
endpoint: endpointDefinition,
};
return new StratosCatalogueEntity(definition);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- <a [routerLink]="nodeLink" (click)="openSidepanelPreview($event)">{{row.metadata.name}}</a> -->
<a href="#" (click)="openSidepanelPreview($event)">{{ row.metadata.name }}</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Component, OnInit } from '@angular/core';

import { PanelPreviewService } from '../../../../../../../core/src/shared/services/panel-preview.service';
import { TableCellCustom } from '../../../../../shared/components/list/list.types';
import {
KubernetesNodePreviewComponent,
} from '../../../kubernetes-node/kubernetes-node-preview/kubernetes-node-preview.component';
import { KubernetesEndpointService } from '../../../services/kubernetes-endpoint.service';
import { KubernetesNode } from '../../../store/kube.types';

@Component({
selector: 'app-kubernetes-node-link',
templateUrl: './kubernetes-node-link.component.html',
styleUrls: ['./kubernetes-node-link.component.scss']
})
export class KubernetesNodeLinkComponent extends TableCellCustom<KubernetesNode> implements OnInit {

public nodeLink;
constructor(
private kubeEndpointService: KubernetesEndpointService,
private panelPreviewService: PanelPreviewService,
) {
super();
}

ngOnInit() {
this.nodeLink = `/kubernetes/${this.kubeEndpointService.kubeGuid}/nodes/${this.row.metadata.name}`;
}

openSidepanelPreview($event: MouseEvent) {
$event.preventDefault();
$event.stopPropagation();
this.panelPreviewService.show(KubernetesNodePreviewComponent, {
nodeName: this.row.metadata.name,
kubeGuid: this.kubeEndpointService.kubeGuid,
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<a *ngIf="( hasMetrics$ | async )" [routerLink]="routerLink">{{row.metadata.name}}</a>
<a href="#" *ngIf="!( hasMetrics$ | async )" (click)="openSidepanelPreview($event)">{{row.metadata.name}}</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';

import { PanelPreviewService } from '../../../../../../../core/src/shared/services/panel-preview.service';
import { EndpointsService } from '../../../../../core/endpoints.service';
import { getIdFromRoute } from '../../../../../core/utils.service';
import { TableCellCustom } from '../../../../../shared/components/list/list.types';
import { KubernetesPodPreviewComponent } from '../../../kubernetes-pod-preview/kubernetes-pod-preview.component';
import { KubernetesEndpointService } from '../../../services/kubernetes-endpoint.service';
import { KubernetesPod } from '../../../store/kube.types';

@Component({
selector: 'app-pod-name-link',
templateUrl: './pod-name-link.component.html',
styleUrls: ['./pod-name-link.component.scss']
})
export class PodNameLinkComponent extends TableCellCustom<KubernetesPod> implements OnInit {
routerLink: string[];
hasMetrics$: Observable<boolean>;
constructor(
private activatedRoute: ActivatedRoute,
private endpointsService: EndpointsService,
private kubeEndpointService: KubernetesEndpointService,
private panelPreviewService: PanelPreviewService,
) {
super();
}

ngOnInit() {
this.hasMetrics$ = this.endpointsService.hasMetrics(this.kubeEndpointService.kubeGuid).pipe(
first()
);
const namespace = getIdFromRoute(this.activatedRoute, 'namespaceName');
if (!namespace) {
this.routerLink = [this.row.metadata.namespace, this.row.metadata.name];
} else {
this.routerLink = [this.row.metadata.name];
}
}

openSidepanelPreview($event: MouseEvent) {
$event.preventDefault();
$event.stopPropagation();
this.panelPreviewService.show(KubernetesPodPreviewComponent, {
podGuid: this.row.metadata.uid,
podName: this.row.metadata.name,
namespaceName: this.row.metadata.namespace,
kubeGuid: this.kubeEndpointService.kubeGuid,
});
}
}
Loading