Skip to content
Merged
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
Expand Up @@ -7,7 +7,7 @@ import { getResourceList } from '@console/shared';
import { referenceForModel, K8sResourceKind } from '@console/internal/module/k8s';
import { RootState } from '@console/internal/redux';
import { safeLoadAll } from 'js-yaml';
import { ServiceBindingRequestModel } from '../../models';
import { ServiceBindingModel } from '../../models';
import { transformTopologyData } from './data-transforms/data-transformer';
import { allowedResources, getHelmReleaseKey, getServiceBindingStatus } from './topology-utils';
import { TopologyDataModel, TopologyDataResources, TrafficData } from './topology-types';
Expand Down Expand Up @@ -124,7 +124,7 @@ export const TopologyDataController: React.FC<TopologyDataControllerProps> = ({
if (serviceBinding) {
resources.push({
isList: true,
kind: referenceForModel(ServiceBindingRequestModel),
kind: referenceForModel(ServiceBindingModel),
namespace,
prop: 'serviceBindingRequests',
optional: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { DeploymentKind, K8sResourceKind } from '@console/internal/module/k8s';
import { apiVersionForModel, DeploymentKind, K8sResourceKind } from '@console/internal/module/k8s';
import { ServiceBindingModel } from '../../../models';
import { TopologyDataResources } from '../topology-types';

export const serviceBindingRequest: K8sResourceKind = {
data: {
apiVersion: 'apps.openshift.io/v1alpha1',
kind: 'ServiceBindingRequest',
apiVersion: apiVersionForModel(ServiceBindingModel),
kind: ServiceBindingModel.kind,
metadata: {
name: 'analytics-deployment-D-wit-deployment-D',
namespace: 'testproject1',
},
spec: {
applicationSelector: {
application: {
group: 'apps',
resource: 'deployments',
resourceRef: 'analytics-deployment',
name: 'analytics-deployment',
version: 'v1',
},
backingServiceSelector: {
group: '',
kind: undefined,
resourceRef: undefined,
version: undefined,
},
services: [
{
group: '',
kind: undefined,
name: undefined,
version: undefined,
},
],
detectBindingResources: true,
},
},
Expand Down Expand Up @@ -79,30 +82,30 @@ export const sbrBackingServiceSelectors: Partial<TopologyDataResources> = {
loadError: null,
data: [
{
apiVersion: 'apps.openshift.io/v1alpha1',
kind: 'ServiceBindingRequest',
apiVersion: apiVersionForModel(ServiceBindingModel),
kind: ServiceBindingModel.kind,
metadata: {
name: 'sbr-1',
},
spec: {
applicationSelector: {
resourceRef: 'app',
application: {
name: 'app',
group: 'apps',
version: 'v1',
resource: 'deployments',
},
backingServiceSelectors: [
services: [
{
group: 'postgresql.baiju.dev',
version: 'v1alpha1',
kind: 'Database',
resourceRef: 'db-demo1',
name: 'db-demo1',
},
{
group: 'postgresql.baiju.dev',
version: 'v1alpha1',
kind: 'Database',
resourceRef: 'db-demo2',
name: 'db-demo2',
},
],
detectBindingResources: true,
Expand Down Expand Up @@ -148,24 +151,26 @@ export const sbrBackingServiceSelector: Partial<TopologyDataResources> = {
loadError: null,
data: [
{
apiVersion: 'apps.openshift.io/v1alpha1',
kind: 'ServiceBindingRequest',
apiVersion: apiVersionForModel(ServiceBindingModel),
kind: ServiceBindingModel.kind,
metadata: {
name: 'sbr-2',
},
spec: {
applicationSelector: {
resourceRef: 'app',
application: {
name: 'app',
group: 'apps',
version: 'v1',
resource: 'deployments',
},
backingServiceSelector: {
group: 'postgresql.baiju.dev',
version: 'v1alpha1',
kind: 'Database',
resourceRef: 'db-demo1',
},
services: [
{
group: 'postgresql.baiju.dev',
version: 'v1alpha1',
kind: 'Database',
name: 'db-demo1',
},
],
detectBindingResources: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,13 @@ export const getTopologyEdgeItems = (
});

_.forEach(edgesFromServiceBinding(dc, sbrs), (sbr) => {
// look for multiple backing services first in `backingServiceSelectors`
// followed by a fallback to the single reference in `backingServiceSelector`
_.forEach(sbr.spec.backingServiceSelectors || [sbr.spec.backingServiceSelector], (bss) => {
_.forEach(sbr.spec.services, (bss) => {
if (bss) {
// handles multiple edges
const targetResource = resources.find(
(deployment) =>
deployment?.metadata?.ownerReferences?.[0]?.kind === bss.kind &&
deployment?.metadata?.ownerReferences?.[0]?.name === bss.resourceRef,
deployment?.metadata?.ownerReferences?.[0]?.name === bss.name,
);
const target = targetResource?.metadata?.uid;
const source = dc?.metadata?.uid;
Expand Down
16 changes: 8 additions & 8 deletions frontend/packages/dev-console/src/models/service-binding.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { K8sKind } from '@console/internal/module/k8s';

export const ServiceBindingRequestModel: K8sKind = {
id: 'servicebindingrequest',
kind: 'ServiceBindingRequest',
plural: 'servicebindingrequests',
label: 'ServiceBindingRequest',
labelPlural: 'ServiceBindingRequests',
abbr: 'SBR',
apiGroup: 'apps.openshift.io',
export const ServiceBindingModel: K8sKind = {
id: 'servicebinding',
kind: 'ServiceBinding',
plural: 'servicebindings',
label: 'ServiceBinding',
labelPlural: 'ServiceBindings',
abbr: 'SB',
apiGroup: 'operators.coreos.com',
apiVersion: 'v1alpha1',
namespaced: true,
crd: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/dev-console/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const plugin: Plugin<ConsumedExtensions> = [
{
type: 'FeatureFlag/Model',
properties: {
model: models.ServiceBindingRequestModel,
model: models.ServiceBindingModel,
flag: ALLOW_SERVICE_BINDING,
},
},
Expand Down
39 changes: 21 additions & 18 deletions frontend/packages/dev-console/src/utils/application-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LabelSelector,
referenceFor,
referenceForModel,
apiVersionForModel,
} from '@console/internal/module/k8s';
import {
ImageStreamModel,
Expand All @@ -31,7 +32,7 @@ import { getOperatorBackedServiceKindMap } from '@console/shared';
import { CREATE_APPLICATION_KEY, UNASSIGNED_KEY } from '../const';
import { TopologyDataObject, ConnectsToData } from '../components/topology/topology-types';
import { detectGitType } from '../components/import/import-validation-utils';
import { ServiceBindingRequestModel } from '../models';
import { ServiceBindingModel } from '../models';

export const sanitizeApplicationValue = (
application: string,
Expand Down Expand Up @@ -68,13 +69,13 @@ export const edgesFromServiceBinding = (
const sourceBindings = [];
_.forEach(sbrs, (sbr) => {
let edgeExists = false;
if (_.get(sbr, 'spec.applicationSelector.resource') === modelFor(referenceFor(source)).plural) {
if (_.get(sbr, 'spec.applicationSelector.resourceRef') === source.metadata.name) {
if (_.get(sbr, 'spec.application.resource') === modelFor(referenceFor(source)).plural) {
if (_.get(sbr, 'spec.application.name') === source.metadata.name) {
edgeExists = true;
} else {
const matchLabels = _.has(sbr, 'spec.applicationSelector.matchLabels');
const matchLabels = _.has(sbr, 'spec.application.matchLabels');
if (matchLabels) {
const sbrSelector = new LabelSelector(sbr.spec.applicationSelector);
const sbrSelector = new LabelSelector(sbr.spec.application);
if (sbrSelector.matches(source)) {
edgeExists = true;
}
Expand Down Expand Up @@ -262,35 +263,37 @@ export const createServiceBinding = (
modelFor(target.kind).abbr
}`;

const serviceBindingRequest = {
apiVersion: 'apps.openshift.io/v1alpha1',
kind: 'ServiceBindingRequest',
const serviceBinding = {
apiVersion: apiVersionForModel(ServiceBindingModel),
kind: ServiceBindingModel.kind,
metadata: {
name: sbrName,
namespace,
},
spec: {
applicationSelector: {
resourceRef: sourceName,
application: {
name: sourceName,
group: sourceGroup[0],
version: sourceGroup[1],
resource: modelFor(referenceFor(source)).plural,
},
backingServiceSelector: {
group: targetResourceGroup[0],
version: targetResourceGroup[1],
kind: targetResourceKind,
resourceRef: targetResourceRefName,
},
services: [
{
group: targetResourceGroup[0],
version: targetResourceGroup[1],
kind: targetResourceKind,
name: targetResourceRefName,
},
],
detectBindingResources: true,
},
};

return k8sCreate(ServiceBindingRequestModel, serviceBindingRequest);
return k8sCreate(ServiceBindingModel, serviceBinding);
};

export const removeServiceBinding = (sbr: K8sResourceKind): Promise<any> => {
return k8sKill(ServiceBindingRequestModel, sbr);
return k8sKill(ServiceBindingModel, sbr);
};

// Get the index of the replaced target of the visual connector
Expand Down