Skip to content

Commit

Permalink
Added cluster param in Istiod status request, Overview page and Masth…
Browse files Browse the repository at this point in the history
…ead (#6170)
  • Loading branch information
hhovsepy committed May 23, 2023
1 parent aa901a4 commit 9ce7013
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 30 deletions.
15 changes: 10 additions & 5 deletions business/istio_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (

// SvcService deals with fetching istio/kubernetes services related content and convert to kiali model
type IstioStatusService struct {
k8s kubernetes.ClientInterface
userClients map[string]kubernetes.ClientInterface
businessLayer *Layer
}

func (iss *IstioStatusService) GetStatus(ctx context.Context) (kubernetes.IstioComponentStatus, error) {
func (iss *IstioStatusService) GetStatus(ctx context.Context, cluster string) (kubernetes.IstioComponentStatus, error) {
var end observability.EndFunc
ctx, end = observability.StartSpan(ctx, "GetStatus",
observability.Attribute("package", "business"),
Expand All @@ -33,15 +33,15 @@ func (iss *IstioStatusService) GetStatus(ctx context.Context) (kubernetes.IstioC
return kubernetes.IstioComponentStatus{}, nil
}

ics, err := iss.getIstioComponentStatus(ctx)
ics, err := iss.getIstioComponentStatus(ctx, cluster)
if err != nil {
return nil, err
}

return ics.Merge(iss.getAddonComponentStatus()), nil
}

func (iss *IstioStatusService) getIstioComponentStatus(ctx context.Context) (kubernetes.IstioComponentStatus, error) {
func (iss *IstioStatusService) getIstioComponentStatus(ctx context.Context, cluster string) (kubernetes.IstioComponentStatus, error) {
// Fetching workloads from component namespaces
workloads, err := iss.getComponentNamespacesWorkloads(ctx)
if err != nil {
Expand All @@ -53,7 +53,12 @@ func (iss *IstioStatusService) getIstioComponentStatus(ctx context.Context) (kub
return kubernetes.IstioComponentStatus{}, err
}

istiodStatus, err := iss.k8s.CanConnectToIstiod()
k8s, ok := iss.userClients[cluster]
if !ok {
return kubernetes.IstioComponentStatus{}, fmt.Errorf("Cluster %s doesn't exist ", cluster)
}

istiodStatus, err := k8s.CanConnectToIstiod()
if err != nil {
return kubernetes.IstioComponentStatus{}, err
}
Expand Down
28 changes: 14 additions & 14 deletions business/istio_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestGrafanaWorking(t *testing.T) {
clients := make(map[string]kubernetes.ClientInterface)
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus
icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)

// Requests to AddOns have to be 1
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestGrafanaDisabled(t *testing.T) {
clients := make(map[string]kubernetes.ClientInterface)
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus
icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)

// Only two Istio components are missing
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestGrafanaNotWorking(t *testing.T) {
clients := make(map[string]kubernetes.ClientInterface)
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus
icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)

// Grafana and two Istio comps missing
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestFailingTracingService(t *testing.T) {
clients := make(map[string]kubernetes.ClientInterface)
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockFailingJaeger).IstioStatus
icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)

// Requests to AddOns have to be 1
Expand All @@ -344,7 +344,7 @@ func TestOverriddenUrls(t *testing.T) {
clients := make(map[string]kubernetes.ClientInterface)
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus
icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)

// Requests to AddOns have to be 1
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestCustomDashboardsMainPrometheus(t *testing.T) {
clients := make(map[string]kubernetes.ClientInterface)
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus
icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)

// Requests to AddOns have to be 1
Expand All @@ -400,7 +400,7 @@ func TestNoIstioComponentFoundError(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s

iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus
_, error := iss.GetStatus(context.TODO())
_, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.Error(error)
}

Expand All @@ -427,7 +427,7 @@ func TestDefaults(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, err := iss.GetStatus(context.TODO())
icsl, err := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(err)
assertComponent(assert, icsl, "istio-ingressgateway", kubernetes.ComponentNotFound, true)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestNonDefaults(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)
assertComponent(assert, icsl, "istio-ingressgateway", kubernetes.ComponentNotFound, false)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)
Expand Down Expand Up @@ -523,7 +523,7 @@ func TestIstiodNotReady(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)
assertComponent(assert, icsl, "istio-ingressgateway", kubernetes.ComponentNotFound, false)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)
Expand Down Expand Up @@ -585,7 +585,7 @@ func TestIstiodUnreachable(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)
assertComponent(assert, icsl, "istio-ingressgateway", kubernetes.ComponentNotFound, false)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)
Expand Down Expand Up @@ -640,7 +640,7 @@ func TestCustomizedAppLabel(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)
assertComponent(assert, icsl, "istio-ingressgateway", kubernetes.ComponentNotFound, false)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)
Expand Down Expand Up @@ -691,7 +691,7 @@ func TestDaemonSetComponentHealthy(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)

Expand Down Expand Up @@ -738,7 +738,7 @@ func TestDaemonSetComponentUnhealthy(t *testing.T) {
clients[conf.KubernetesConfig.ClusterName] = k8s
iss := NewWithBackends(clients, clients, nil, mockJaeger).IstioStatus

icsl, error := iss.GetStatus(context.TODO())
icsl, error := iss.GetStatus(context.TODO(), conf.KubernetesConfig.ClusterName)
assert.NoError(error)
assertComponent(assert, icsl, "istio-ingressgateway", kubernetes.ComponentUnhealthy, false)
assertComponent(assert, icsl, "istio-egressgateway", kubernetes.ComponentUnhealthy, false)
Expand Down
2 changes: 1 addition & 1 deletion business/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func NewWithBackends(userClients map[string]kubernetes.ClientInterface, kialiSAC
temporaryLayer.App = AppService{prom: prom, userClients: userClients, businessLayer: temporaryLayer}
temporaryLayer.Health = HealthService{prom: prom, businessLayer: temporaryLayer, userClients: userClients}
temporaryLayer.IstioConfig = IstioConfigService{config: *config.Get(), userClients: userClients, kialiCache: kialiCache, businessLayer: temporaryLayer}
temporaryLayer.IstioStatus = IstioStatusService{k8s: userClients[homeClusterName], businessLayer: temporaryLayer}
temporaryLayer.IstioStatus = IstioStatusService{userClients: userClients, businessLayer: temporaryLayer}
temporaryLayer.IstioCerts = IstioCertsService{k8s: userClients[homeClusterName], businessLayer: temporaryLayer}
temporaryLayer.Jaeger = JaegerService{loader: jaegerClient, businessLayer: temporaryLayer}
temporaryLayer.k8sClients = userClients
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/IstioStatus/IstioStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type StatusIcons = {
type Props = ReduxProps & {
lastRefreshAt: TimeInMilliseconds;
icons?: StatusIcons;
cluster?: string;
};

const ValidToColor = {
Expand Down Expand Up @@ -70,7 +71,7 @@ export class IstioStatus extends React.Component<Props> {
}

fetchStatus = () => {
API.getIstioStatus()
API.getIstioStatus(this.props.cluster)
.then(response => {
return this.props.setIstioStatus(response.data);
})
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/IstioStatus/IstioStatusInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
MinusCircleIcon
} from '@patternfly/react-icons';

export default function IstioStatusInline() {
type Props = {
cluster?: string;
};

export default function IstioStatusInline({ cluster }: Props) {
return (
<IstioStatus
icons={{
Expand All @@ -16,6 +20,7 @@ export default function IstioStatusInline() {
InfoIcon: MinusCircleIcon,
WarningIcon: ExclamationTriangleIcon
}}
cluster={cluster}
/>
);
}
2 changes: 1 addition & 1 deletion frontend/src/components/Nav/Masthead/Masthead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MastheadItems extends React.Component {
)}
</FlexItem>
<FlexItem>
<IstioStatus />
<IstioStatus cluster={serverConfig.clusterInfo?.name} />
</FlexItem>
<FlexItem>
<MeshMTLSStatus />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/VirtualList/Renderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const nsItem: Renderer<NamespaceInfo> = (ns: NamespaceInfo, _config: Reso
<td role="gridcell" key={'VirtuaItem_NamespaceItem_' + ns.name} style={{ verticalAlign: 'middle' }}>
<PFBadge badge={badge} />
{ns.name}
{ns.name === serverConfig.istioNamespace && <ControlPlaneBadge />}
{ns.name === serverConfig.istioNamespace && <ControlPlaneBadge cluster={ns.cluster} />}
</td>
);
};
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/pages/Overview/ControlPlaneBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import IstioStatusInline from '../../components/IstioStatus/IstioStatusInline';
import { serverConfig } from '../../config';
import AmbientBadge from '../../components/Ambient/AmbientBadge';

class ControlPlaneBadge extends React.Component<{}> {
type Props = {
cluster?: string;
};

class ControlPlaneBadge extends React.Component<Props> {
render() {
return (
<>
<Label style={{ marginLeft: 5 }} color="green" isCompact>
Control plane
</Label>
{serverConfig.ambientEnabled && <AmbientBadge tooltip={true}></AmbientBadge>} <IstioStatusInline />
{serverConfig.ambientEnabled && <AmbientBadge tooltip={true}></AmbientBadge>}{' '}
<IstioStatusInline cluster={this.props.cluster} />
</>
);
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/pages/Overview/OverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,9 @@ export class OverviewPage extends React.Component<OverviewProps, State> {
title={ns.name}
>
{ns.name}
{ns.name === serverConfig.istioNamespace && <ControlPlaneBadge></ControlPlaneBadge>}
{ns.name === serverConfig.istioNamespace && (
<ControlPlaneBadge cluster={ns.cluster}></ControlPlaneBadge>
)}
{ns.name !== serverConfig.istioNamespace &&
this.hasCanaryUpgradeConfigured() &&
this.state.canaryUpgradeStatus?.migratedNamespaces.includes(ns.name) && (
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/services/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ export const getOutboundTrafficPolicyMode = () => {
return newRequest<OutboundTrafficPolicy>(HTTP_VERBS.GET, urls.outboundTrafficPolicyMode(), {}, {});
};

export const getIstioStatus = () => {
return newRequest<ComponentStatus[]>(HTTP_VERBS.GET, urls.istioStatus(), {}, {});
export const getIstioStatus = (cluster?: string) => {
const queryParams: any = {};
if (cluster) {
queryParams.cluster = cluster;
}
return newRequest<ComponentStatus[]>(HTTP_VERBS.GET, urls.istioStatus(), queryParams, {});
};

export const getIstioCertsInfo = () => {
Expand Down
2 changes: 1 addition & 1 deletion handlers/istio_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func IstioStatus(w http.ResponseWriter, r *http.Request) {
return
}

istioStatus, err := business.IstioStatus.GetStatus(r.Context())
istioStatus, err := business.IstioStatus.GetStatus(r.Context(), clusterNameFromQuery(r.URL.Query()))
if err != nil {
handleErrorResponse(w, err)
return
Expand Down

0 comments on commit 9ce7013

Please sign in to comment.