Skip to content

Commit

Permalink
Fix: ServiceBinding resources are not deployed with odo deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Aug 17, 2022
1 parent 60c9a78 commit 3836e46
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func ApplyKubernetes(mode, appName string, devfile parser.DevfileObj, kubernetes

// Deploy the actual Kubernetes component and error out if there's an issue.
log.Sectionf("Deploying Kubernetes Component: %s", u.GetName())
_, err = service.PushKubernetesResource(kubeClient, u, labels, annotations)
_, err = service.PushKubernetesResource(kubeClient, u, labels, annotations, true)
if err != nil {
return fmt.Errorf("failed to create service(s) associated with the component: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func PushKubernetesResources(client kclient.ClientInterface, devfileObj parser.D
if er != nil {
return er
}
_, er = PushKubernetesResource(client, u, labels, annotations)
_, er = PushKubernetesResource(client, u, labels, annotations, false)
if er != nil {
return er
}
Expand All @@ -241,8 +241,9 @@ func PushKubernetesResources(client kclient.ClientInterface, devfileObj parser.D

// PushKubernetesResource pushes a Kubernetes resource (u) to the cluster using client
// adding labels to the resource
func PushKubernetesResource(client kclient.ClientInterface, u unstructured.Unstructured, labels map[string]string, annotations map[string]string) (bool, error) {
if isLinkResource(u.GetKind()) {
// allowSB decides if the ServiceBinding kind should be allowed to deploy
func PushKubernetesResource(client kclient.ClientInterface, u unstructured.Unstructured, labels map[string]string, annotations map[string]string, allowSB bool) (bool, error) {
if isLinkResource(u.GetKind()) && !allowSB {
// it's a service binding related resource
return false, nil
}
Expand Down
162 changes: 162 additions & 0 deletions tests/examples/source/devfiles/nodejs/devfile-deploy-with-SB.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
workingDir: /project
id: test
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- apply:
component: outerloop-service
id: deploy-service
- apply:
component: my-nodejs-app-cluster-sample
id: deploy-binding
- id: deploy
composite:
commands:
- build-image
- deployk8s
- deploy-service
- deploy-binding
group:
kind: deploy
isDefault: true
components:
- container:
endpoints:
- name: http-3000
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
name: runtime
- name: outerloop-build
image:
imageName: "{{CONTAINER_IMAGE}}"
dockerfile:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
rootRequired: false

- name: outerloop-deploy
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-component
spec:
replicas: 1
selector:
matchLabels:
app: node-app
template:
metadata:
labels:
app: node-app
spec:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
resources:
limits:
memory: "128Mi"
cpu: "500m"
- kubernetes:
deployByDefault: false
inlined: |
apiVersion: v1
kind: Service
metadata:
labels:
app: node-app
name: my-component
spec:
ports:
- name: http-3000
port: 3000
protocol: TCP
targetPort: 3000
selector:
app: node-app
type: LoadBalancer
name: outerloop-service
- kubernetes:
deployByDefault: false
inlined: |
apiVersion: binding.operators.coreos.com/v1alpha1
kind: ServiceBinding
metadata:
name: my-nodejs-app-cluster-sample
spec:
application:
group: apps
kind: Deployment
name: my-component
version: v1
bindAsFiles: true
detectBindingResources: true
services:
- group: postgresql.k8s.enterprisedb.io
id: my-nodejs-app-cluster-sample
kind: Cluster
name: cluster-sample
resource: clusters
version: v1
status:
secret: ""
name: my-nodejs-app-cluster-sample

metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: nodejs-prj1-api-abhz
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.2.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
variables:
CONTAINER_IMAGE: quay.io/unknown-account/myimage
27 changes: 27 additions & 0 deletions tests/integration/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,33 @@ var _ = Describe("odo devfile deploy command tests", func() {
}
})

When("deploying a ServiceBinding k8s resource", func() {
const serviceBindingName = "my-nodejs-app-cluster-sample" // hard-coded from devfile-deploy-with-SB.yaml
BeforeEach(func() {
commonVar.CliRunner.EnsureOperatorIsInstalled("service-binding-operator")
commonVar.CliRunner.EnsureOperatorIsInstalled("cloud-native-postgresql")
Eventually(func() string {
out, _ := commonVar.CliRunner.GetBindableKinds()
return out
}, 120, 3).Should(ContainSubstring("Cluster"))
addBindableKind := commonVar.CliRunner.Run("apply", "-f", helper.GetExamplePath("manifests", "bindablekind-instance.yaml"))
Expect(addBindableKind.ExitCode()).To(BeEquivalentTo(0))
})
When("odo deploy is run", func() {
BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-deploy-with-SB.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
helper.Cmd("odo", "deploy").AddEnv("PODMAN_CMD=echo").ShouldPass()
})
It("should successfully deploy the ServiceBinding resource", func() {
out, err := commonVar.CliRunner.GetServiceBinding(serviceBindingName, commonVar.Project)
Expect(out).ToNot(BeEmpty())
Expect(err).To(BeEmpty())
})
})

})

When("using a devfile.yaml containing an Image component with no build context", func() {

BeforeEach(func() {
Expand Down

0 comments on commit 3836e46

Please sign in to comment.