Skip to content

Commit

Permalink
fix(online): ENTESB-17741 Open pod details leads to Page Not Found
Browse files Browse the repository at this point in the history
  • Loading branch information
tadayosi committed Jun 8, 2022
1 parent ed15239 commit 0006e60
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
7 changes: 3 additions & 4 deletions packages/common/src/openshift/openshift.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Online {

const OS4 = {
'dc': 'deploymentconfigs',
'rc': 'replicationcontrollers',
'rs': 'replicasets',
};

function openshiftLinkDirective(
Expand All @@ -33,10 +33,9 @@ namespace Online {
link: function ($scope: ng.IScope | any) {
$q.all([openShiftService.getClusterVersion(), openShiftConsole.url])
.then(([clusterVersion, consoleUrl]) => {
const major = parseInt((clusterVersion || '3').split('.')[0], 10);
if (consoleUrl) {
if (major >= 4) {
$scope.url = UrlHelpers.join(consoleUrl, 'k8s', 'ns', $scope.namespace, OS4[$scope.resources] || $scope.resources, $scope.name);
if (isOpenShift4(clusterVersion)) {
$scope.url = UrlHelpers.join(consoleUrl, 'k8s/ns', $scope.namespace, (OS4[$scope.resources] || $scope.resources), $scope.name);
} else {
$scope.url = UrlHelpers.join(consoleUrl, 'project', $scope.namespace, 'browse', $scope.resources, $scope.name);
}
Expand Down
9 changes: 7 additions & 2 deletions packages/common/src/openshift/openshift.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ namespace Online {
if (!this.$window.OPENSHIFT_CONFIG || !this.$window.OPENSHIFT_CONFIG.openshift) {
return this.$q.resolve(undefined);
}
const cluster_version = this.$window.OPENSHIFT_CONFIG.openshift.cluster_version;
const clusterVersion = this.$window.OPENSHIFT_CONFIG.openshift.cluster_version;
// We may want to get the ClusterVersion resource using the Config API available in OpenShift 4
return this.$q.resolve(cluster_version);
return this.$q.resolve(clusterVersion);
}

is(mode: HawtioMode): boolean {
Expand All @@ -128,4 +128,9 @@ namespace Online {
});
}
}

export function isOpenShift4(clusterVersion: string): boolean {
const major = parseInt((clusterVersion || '4').split('.')[0], 10);
return major >= 4;
}
}
4 changes: 2 additions & 2 deletions packages/online/src/discover/discover.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ <h1>
{{pod.config}}
</openshift-link>
,
<openshift-link namespace="pod.namespace" resources="'rc'" name="pod.deployment">
<openshift-link namespace="pod.namespace" resources="'rs'" name="pod.deployment">
#{{pod.version}}
</openshift-link>
</div>
<div ng-if="!pod.config" class="list-group-item-heading">
<div class="component-label">Deployment</div>
<openshift-link namespace="pod.namespace" resources="'rc'" name="pod.name">
<openshift-link namespace="pod.namespace" resources="'rs'" name="pod.deployment">
{{pod.deployment}}
</openshift-link>
</div>
Expand Down
17 changes: 14 additions & 3 deletions packages/online/src/discover/discover.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Online {
}

function connectUrlFilter() {
return (pod, port = 8778) => {
return (pod: Pod, port = 8778) => {
const jolokiaPath = getManagementJolokiaPath(pod, port);
return new URI().path('/integration/')
.query({
Expand All @@ -86,8 +86,19 @@ namespace Online {
};
}

function podDetailsUrlFilter() {
return (pod, openShiftConsoleUrl: string) => UrlHelpers.join(openShiftConsoleUrl, 'project', pod.metadata.namespace, 'browse/pods', pod.metadata.name);
function podDetailsUrlFilter(openShiftService: OpenShiftService) {
'ngInject';
let os4 = false;
openShiftService.getClusterVersion().then((clusterVersion => {
os4 = isOpenShift4(clusterVersion);
}));
return (pod: Pod, openShiftConsoleUrl: string) => {
if (os4) {
return UrlHelpers.join(openShiftConsoleUrl, 'k8s/ns', pod.metadata.namespace, 'pods', pod.metadata.name);
} else {
return UrlHelpers.join(openShiftConsoleUrl, 'project', pod.metadata.namespace, 'browse/pods', pod.metadata.name);
}
};
}

hawtioPluginLoader.addModule(discoverModule);
Expand Down
9 changes: 8 additions & 1 deletion packages/online/src/labels/labels.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Online {
constructor(
$location: ng.ILocationService,
$timeout: ng.ITimeoutService,
openShiftService: OpenShiftService,
) {
'ngInject';
}
Expand All @@ -42,7 +43,13 @@ namespace Online {
scope.filterAndNavigate = function (key, value) {
if (scope.kind && scope.projectName) {
if (!scope.filterCurrentPage) {
this.$location.url(scope.navigateUrl || `/project/${scope.projectName}/browse/${scope.kind}`);
this.openShiftService.getClusterVersion().then((clusterVersion: string) => {
if (isOpenShift4(clusterVersion)) {
this.$location.url(scope.navigateUrl || `/k8s/ns/${scope.projectName}/${scope.kind}`);
} else {
this.$location.url(scope.navigateUrl || `/project/${scope.projectName}/browse/${scope.kind}`);
}
})
}
this.$timeout(function () {
const selector = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/online/src/labels/labels.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Online {
.filter('hashSize', hashSizeFilter)
.name;

function labelsDirective($location: ng.ILocationService, $timeout: ng.ITimeoutService) {
function labelsDirective($location: ng.ILocationService, $timeout: ng.ITimeoutService, openShiftService: OpenShiftService) {
'ngInject';
return new LabelsDirective($location, $timeout);
return new LabelsDirective($location, $timeout, openShiftService);
}

function hashSizeFilter() {
Expand Down

0 comments on commit 0006e60

Please sign in to comment.