Skip to content

Commit

Permalink
fix(kubernetes): Use apiGroup when looking up deploy status for CRDs (s…
Browse files Browse the repository at this point in the history
…pinnaker#6691)

Part of the fix for spinnaker/spinnaker#3387.
Relates to spinnaker/clouddriver#3003.  Without this change, the
status pills (stable, available, etc) would not be found for CRD
manifests.
  • Loading branch information
willgorman authored and ezimanyi committed Mar 18, 2019
1 parent a5a54bd commit 57c30b5
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import {
import { KubernetesManifestService } from 'kubernetes/v2/manifest/manifest.service';
import { ManifestStatus } from './ManifestStatus';

// from https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/
const BUILT_IN_GROUPS = ['', 'core', 'batch', 'apps', 'extensions', 'storage.k8s.io',
'apiextensions.k8s.io', 'apiregistration.k8s.io', 'policy', 'scheduling.k8s.io',
'settings.k8s.io', 'authorization.k8s.io', 'authentication.k8s.io', 'rbac.authorization.k8s.io',
'certifcates.k8s.io', 'networking.k8s.io']

export interface IManifestSubscription {
id: string;
unsubscribe: () => void;
Expand All @@ -17,6 +23,7 @@ export interface IManifestSubscription {

interface IStageManifest {
kind: string;
apiVersion: string;
metadata: {
namespace: string;
name: string;
Expand Down Expand Up @@ -64,7 +71,7 @@ export class DeployStatus extends React.Component<IExecutionDetailsSectionProps,
private subscribeToManifestUpdates(id: string, manifest: IStageManifest): () => void {
const params = {
account: this.props.stage.context.account,
name: upperFirst(manifest.kind) + ' ' + manifest.metadata.name,
name: this.scopedKind(manifest) + ' ' + manifest.metadata.name,
location: manifest.metadata.namespace == null ? '_' : manifest.metadata.namespace,
};
return KubernetesManifestService.subscribe(this.props.application, params, (updated: IManifest) => {
Expand All @@ -87,7 +94,31 @@ export class DeployStatus extends React.Component<IExecutionDetailsSectionProps,
// manifest.metadata.namespace doesn't exist if it's a namespace being deployed
const namespace = (manifest.metadata.namespace || '_').toLowerCase();
const name = manifest.metadata.name.toLowerCase();
return `${namespace} ${kind} ${name}`;
const apiVersion = manifest.apiVersion.toLowerCase();
// assuming this identifier is opaque and not parsed anywhere. Including the
// apiVersion will prevent collisions with CRD kinds without having any visible
// effect elsewhere
return `${namespace} ${kind} ${apiVersion} ${name}`;
}

private apiGroup(manifest: IStageManifest): string {
const parts = manifest.apiVersion.split('/');
if (parts.length < 2) {
return ''
}
return parts[0]
}

private isCRDGroup(manifest: IStageManifest): boolean {
return !BUILT_IN_GROUPS.includes(this.apiGroup(manifest));
}

private scopedKind(manifest: IStageManifest): string {
if (this.isCRDGroup(manifest)) {
return upperFirst(manifest.kind) + '.' + this.apiGroup(manifest);
}

return upperFirst(manifest.kind)
}

private stageManifestToIManifest(manifest: IStageManifest, account: string): IManifest {
Expand Down

0 comments on commit 57c30b5

Please sign in to comment.