-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDAP-19300 adding container injection feature and Dockerfile for unit testing on Docker image #89
base: develop
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ss, err := getCDAPServiceSpec(master, s) | ||
statefulSet, err := getCDAPStatefulServiceSpec(master, s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if block seems to be duplicated on line 357.
"protocol":"test-protocol" | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing newline at end of file.
"protocol":"test-protocol" | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing newline at end of file. Check in other test files also.
"protocol":"test-protocol" | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing newline at end of file.
templates/cdap-deployment.yaml
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -97,7 +97,17 @@ spec: | |||
env: | |||
{{range $e := $c.Env }} | |||
- name: "{{$e.Name}}" | |||
value: "{{$e.Value}}" | |||
{{if $e.Value}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be including kubebuilder_1.0.8_darwin_amd64.tar.gz? Otherwise, everything else looks mostly good to me aside from some minor nit comments.
///////////////////////////////////////////////////////// | ||
///// Handling reconciling ConfigMapHandler objects ///// | ||
///////////////////////////////////////////////////////// | ||
// /////////////////////////////////////////////////////// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no additional space
/////////////////////////////////////////////////////////// | ||
///// Handling reconciling deployment of all services ///// | ||
/////////////////////////////////////////////////////////// | ||
// ///////////////////////////////////////////////////////// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no spaces
/////////////////////////////////////////////////////// | ||
///// Handler for image version upgrade/downgrade ///// | ||
/////////////////////////////////////////////////////// | ||
// ///////////////////////////////////////////////////// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no spaces
This change refers to the ticket CDAP-19300 - https://cdap.atlassian.net/browse/CDAP-19300.
In this change, we introduced:
Dockerfile.test
specifically used to run unit test on a Docker image