CDAP-19300 adding container injection feature and Dockerfile for unit testing on Docker image#89
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). For more information, open the CLA check for this pull request. |
73c000c to
9fb33d2
Compare
2d8e131 to
3e2c1a8
Compare
e3d60e4 to
e5ad0e8
Compare
api/v1alpha1/cdapmaster_types.go
Outdated
| // Containers define any additional containers a service has | ||
| // This is a list of containers and can be left blank | ||
| // A typical use is to add sidecars for a deployment | ||
| Containers []*corev1.Container `json:"containers,omitempty"` |
There was a problem hiding this comment.
Can we move this to the CDAPServiceSpec? That way we don't have to duplicate code in statefulset and deployment.
There was a problem hiding this comment.
Thanks for your review @dli357 I have now moved the Containers definitions to the CDAPServiceSpec struct. Please let me know if there is anything else you would like me to change. Thank you
|
Thank you @dli357 I have now uploaded a new commit version |
arjan-bal
left a comment
There was a problem hiding this comment.
Thanks for contributing! Left some comments.
controllers/cdapmaster_controller.go
Outdated
| if spec.Config[confRouterServerAddress] == "" { | ||
| spec.Config[confRouterServerAddress] = fmt.Sprintf("cdap-%s-%s", r.Name, strings.ToLower(string(serviceRouter))) | ||
| } | ||
|
|
There was a problem hiding this comment.
nit: Can we remove blank lines between "if" blocks if they're related. In this case, there are 3 if blocks that "Set the configMapCConf entry for the router and UI service and ports". I think a blank line should come after the 3 if blocks.
controllers/deployment.go
Outdated
| // Add each service as a container | ||
| for _, s := range services { | ||
| ss, err := getCDAPServiceSpec(master, s) | ||
| statefulSet, err := getCDAPStatefulServiceSpec(master, s) |
There was a problem hiding this comment.
Why is this change required? Since Containers field is present in CDAPServiceSpec, we could access it without getting a statefulSet spec or ScalableServiceSpec.
controllers/deployment.go
Outdated
| return nil, err | ||
| } | ||
| if _, err := spec.addAdditionalVolumeMounts(ss.AdditionalVolumeMounts); err != nil { | ||
| if _, err := spec.addAdditionalVolumeMounts(scalableSpec.CDAPServiceSpec.AdditionalVolumeMounts); err != nil { |
There was a problem hiding this comment.
This if block seems to be duplicated on line 360.
controllers/deployment.go
Outdated
| return nil, err | ||
| } | ||
| if _, err := spec.addAdditionalVolumes(ss.AdditionalVolumes); err != nil { | ||
| if _, err := spec.addAdditionalVolumes(scalableSpec.CDAPServiceSpec.AdditionalVolumes); err != nil { |
There was a problem hiding this comment.
This if block seems to be duplicated on line 357.
| "protocol":"test-protocol" | ||
| } | ||
| ] | ||
| } No newline at end of file |
There was a problem hiding this comment.
nit: missing newline at end of file.
| "protocol":"test-protocol" | ||
| } | ||
| ] | ||
| } No newline at end of file |
There was a problem hiding this comment.
nit: missing newline at end of file. Check in other test files also.
| "protocol":"test-protocol" | ||
| } | ||
| ] | ||
| } No newline at end of file |
There was a problem hiding this comment.
nit: missing newline at end of file.
templates/cdap-deployment.yaml
Outdated
| {{if $c.LivenessProbe}} | ||
| livenessProbe: | ||
| {{if $c.LivenessProbe.InitialDelaySeconds }} | ||
| initialDelaySeconds: {{$c.LivenessProbe.InitialDelaySeconds }} | ||
| {{end}} | ||
| {{if $c.LivenessProbe.TimeoutSeconds }} | ||
| timeoutSeconds: {{$c.LivenessProbe.TimeoutSeconds }} | ||
| {{end}} | ||
| {{if $c.LivenessProbe.PeriodSeconds }} | ||
| periodSeconds: {{$c.LivenessProbe.PeriodSeconds }} | ||
| {{end}} | ||
| {{if $c.LivenessProbe.SuccessThreshold }} | ||
| successThreshold: {{$c.LivenessProbe.SuccessThreshold }} | ||
| {{end}} | ||
| {{if $c.LivenessProbe.FailureThreshold }} | ||
| failureThreshold: {{$c.LivenessProbe.FailureThreshold }} | ||
| {{end}} | ||
|
|
||
| {{if $c.LivenessProbe.Handler}} | ||
|
|
||
| {{if $c.LivenessProbe.Handler.HTTPGet}} | ||
| httpGet: | ||
| {{if $c.LivenessProbe.Handler.HTTPGet.Path}} | ||
| path: {{$c.LivenessProbe.Handler.HTTPGet.Path}} | ||
| {{end}} | ||
| port: {{$c.LivenessProbe.Handler.HTTPGet.Port}} | ||
| {{if $c.LivenessProbe.Handler.HTTPGet.Scheme}} | ||
| scheme: {{$c.LivenessProbe.Handler.HTTPGet.Scheme}} | ||
| {{end}} | ||
| {{if $c.LivenessProbe.Handler.HTTPGet.Host}} | ||
| host: {{$c.LivenessProbe.Handler.HTTPGet.Host}} | ||
| {{end}} | ||
| {{if $c.LivenessProbe.Handler.HTTPGet.HTTPHeaders}} | ||
| httpHeaders: | ||
| {{range $h := $c.LivenessProbe.Handler.HTTPGet.HTTPHeaders }} | ||
| - name: {{$h.Name}} | ||
| value: {{$h.Value}} | ||
| {{end}} | ||
| {{end}} | ||
| {{end}} | ||
|
|
||
| {{if $c.LivenessProbe.Handler.Exec}} | ||
| exec: | ||
| command: | ||
| {{range $v := $c.LivenessProbe.Handler.Exec.Command }} | ||
| - {{$v}} | ||
| {{end}} | ||
| {{end}} | ||
|
|
||
| {{if $c.LivenessProbe.Handler.TCPSocket}} | ||
| tcpSocket: | ||
| port: {{$c.LivenessProbe.Handler.TCPSocket.Port}} | ||
| {{end}} | ||
|
|
||
| {{end}} | ||
|
|
||
| {{end}} | ||
|
|
||
| {{if $c.ReadinessProbe}} | ||
| readinessProbe: | ||
| {{if $c.ReadinessProbe.InitialDelaySeconds }} | ||
| initialDelaySeconds: {{$c.ReadinessProbe.InitialDelaySeconds }} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.TimeoutSeconds }} | ||
| timeoutSeconds: {{$c.ReadinessProbe.TimeoutSeconds }} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.PeriodSeconds }} | ||
| periodSeconds: {{$c.ReadinessProbe.PeriodSeconds }} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.SuccessThreshold }} | ||
| successThreshold: {{$c.ReadinessProbe.SuccessThreshold }} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.FailureThreshold }} | ||
| failureThreshold: {{$c.ReadinessProbe.FailureThreshold }} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.Handler}} | ||
|
|
||
| {{if $c.ReadinessProbe.Handler.HTTPGet}} | ||
| httpGet: | ||
| {{if $c.ReadinessProbe.Handler.HTTPGet.Path}} | ||
| path: {{$c.ReadinessProbe.Handler.HTTPGet.Path}} | ||
| {{end}} | ||
| port: {{$c.ReadinessProbe.Handler.HTTPGet.Port}} | ||
| {{if $c.ReadinessProbe.Handler.HTTPGet.Scheme}} | ||
| scheme: {{$c.ReadinessProbe.Handler.HTTPGet.Scheme}} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.Handler.HTTPGet.Host}} | ||
| host: {{$c.ReadinessProbe.Handler.HTTPGet.Host}} | ||
| {{end}} | ||
| {{if $c.ReadinessProbe.Handler.HTTPGet.HTTPHeaders}} | ||
| httpHeaders: | ||
| {{range $h := $c.ReadinessProbe.Handler.HTTPGet.HTTPHeaders }} | ||
| - name: {{$h.Name}} | ||
| value: {{$h.Value}} | ||
| {{end}} | ||
| {{end}} | ||
| {{end}} | ||
|
|
||
| {{if $c.ReadinessProbe.Handler.Exec}} | ||
| exec: | ||
| command: | ||
| {{range $v := $c.ReadinessProbe.Handler.Exec.Command }} | ||
| - {{$v}} | ||
| {{end}} | ||
| {{end}} | ||
|
|
||
| {{if $c.ReadinessProbe.Handler.TCPSocket}} | ||
| tcpSocket: | ||
| port: {{$c.ReadinessProbe.Handler.TCPSocket.Port}} | ||
| {{end}} | ||
|
|
||
| {{end}} | ||
|
|
||
| {{end}} | ||
|
|
||
| {{if $c.Ports}} | ||
| ports: | ||
| {{range $cp := $c.Ports}} | ||
| - containerPort: {{$cp.ContainerPort}} | ||
| {{if $cp.Name}} | ||
| name: {{$cp.Name}} | ||
| {{end}} | ||
| {{if $cp.Protocol}} | ||
| protocol: {{$cp.Protocol}} | ||
| {{end}} | ||
| {{if $cp.HostPort}} | ||
| hostPort: {{$cp.HostPort}} | ||
| {{end}} | ||
| {{if $cp.HostIP}} | ||
| hostIP: {{$cp.HostIP}} | ||
| {{end}} | ||
| {{end}} | ||
| {{end}} |
There was a problem hiding this comment.
Instead of adding these properties through templates, I think it will be lesser code and more flexible if you merge the fields using go code.
Eg PR: https://github.com/cdapio/cdap-operator/pull/79/files
Code that needs to be changed: https://github.com/cdapio/cdap-operator/blob/develop/controllers/deployment.go#L460-L465
controllers/deployment_test.go
Outdated
| expectedContainerJson := readExpectedJson(expectedJsonFilename) | ||
| diffJson(actualContainerJson, expectedContainerJson) | ||
| } | ||
| It("Multiple Additional containers for Router", func() { |
There was a problem hiding this comment.
nit: I think this should read like a sentence: "It should add multiple containers fro Router". Similarly for other tests.
|
Thank you for all your great feedback @arjan-bal! I have now uploaded a new commit version. |
templates/cdap-deployment.yaml
Outdated
| {{range $e := $c.Env }} | ||
| - name: "{{$e.Name}}" | ||
| value: "{{$e.Value}}" | ||
| {{if $e.Value}} |
There was a problem hiding this comment.
Like the other comment regarding moving the container to go code, we should do the same for environment variables if we want to support ValueFrom. This will significantly simplify the generation logic since we can just directly add the container/envvar to the YAML instead of relying on templating.
Additionally, can we also add this to cdap-sts.yaml to keep environment variables consistent across all containers? Thanks!
There was a problem hiding this comment.
Thanks for your review @dli357 . I have now moved the environment variables to go code. Could you please have a further look and let me know? Thank you
57d0ed0 to
21cf8d0
Compare
|
@arjan-bal @dli357 I have uploaded a new version which considers all your comments (thank you). Could you please review it? |
| ///////////////////////////////////////////////////////// | ||
| ///// Handling reconciling ConfigMapHandler objects ///// | ||
| ///////////////////////////////////////////////////////// | ||
| // /////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// | ||
| ///// Handling reconciling deployment of all services ///// | ||
| /////////////////////////////////////////////////////////// | ||
| // ///////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////// | ||
| ///// Handler for image version upgrade/downgrade ///// | ||
| /////////////////////////////////////////////////////// | ||
| // ///////////////////////////////////////////////////// |
This change refers to the ticket CDAP-19300 - https://cdap.atlassian.net/browse/CDAP-19300.
In this change, we introduced:
Dockerfile.testspecifically used to run unit test on a Docker image