Skip to content
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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

mariogiuffrida
Copy link

@mariogiuffrida mariogiuffrida commented May 18, 2022

This change refers to the ticket CDAP-19300 - https://cdap.atlassian.net/browse/CDAP-19300.

In this change, we introduced:

  • the possibility of injecting containers inside Stateful and Deployment services.
  • the possibility to override the service ports (i.e. router listening on non-default ports)
  • a new Dockerfile.test specifically used to run unit test on a Docker image

@google-cla
Copy link

google-cla bot commented May 18, 2022

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.

@mariogiuffrida mariogiuffrida changed the base branch from develop to master May 18, 2022 10:21
@mariogiuffrida mariogiuffrida changed the base branch from master to develop May 18, 2022 10:21
@mariogiuffrida mariogiuffrida force-pushed the CDAP-19300-container-injection-feature branch from 73c000c to 9fb33d2 Compare May 24, 2022 10:23
@mariogiuffrida mariogiuffrida changed the title Cdap 19300 container injection feature CDAP-19300 adding container injection feature and Dockerfile for unit testing on Docker image May 24, 2022
@mariogiuffrida mariogiuffrida force-pushed the CDAP-19300-container-injection-feature branch 2 times, most recently from 2d8e131 to 3e2c1a8 Compare May 24, 2022 11:18
@mariogiuffrida mariogiuffrida marked this pull request as ready for review May 24, 2022 11:29
@mariogiuffrida mariogiuffrida force-pushed the CDAP-19300-container-injection-feature branch 2 times, most recently from e3d60e4 to e5ad0e8 Compare May 24, 2022 14:02
// 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"`
Copy link
Contributor

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.

Copy link
Author

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

@mariogiuffrida
Copy link
Author

Thank you @dli357 I have now uploaded a new commit version

@arjan-bal arjan-bal self-requested a review August 30, 2022 17:00
Copy link
Contributor

@arjan-bal arjan-bal left a 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.

if spec.Config[confRouterServerAddress] == "" {
spec.Config[confRouterServerAddress] = fmt.Sprintf("cdap-%s-%s", r.Name, strings.ToLower(string(serviceRouter)))
}

Copy link
Contributor

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.

ss, err := getCDAPServiceSpec(master, s)
statefulSet, err := getCDAPStatefulServiceSpec(master, s)
Copy link
Contributor

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.

return nil, err
}
if _, err := spec.addAdditionalVolumeMounts(ss.AdditionalVolumeMounts); err != nil {
if _, err := spec.addAdditionalVolumeMounts(scalableSpec.CDAPServiceSpec.AdditionalVolumeMounts); err != nil {
Copy link
Contributor

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.

return nil, err
}
if _, err := spec.addAdditionalVolumes(ss.AdditionalVolumes); err != nil {
if _, err := spec.addAdditionalVolumes(scalableSpec.CDAPServiceSpec.AdditionalVolumes); err != nil {
Copy link
Contributor

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"
}
]
}
Copy link
Contributor

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"
}
]
}
Copy link
Contributor

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"
}
]
}
Copy link
Contributor

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.

Comment on lines 126 to 258
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}}
Copy link
Contributor

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

expectedContainerJson := readExpectedJson(expectedJsonFilename)
diffJson(actualContainerJson, expectedContainerJson)
}
It("Multiple Additional containers for Router", func() {
Copy link
Contributor

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.

@mariogiuffrida
Copy link
Author

Thank you for all your great feedback @arjan-bal! I have now uploaded a new commit version.

@@ -97,7 +97,17 @@ spec:
env:
{{range $e := $c.Env }}
- name: "{{$e.Name}}"
value: "{{$e.Value}}"
{{if $e.Value}}
Copy link
Contributor

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!

Copy link
Author

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

@mariogiuffrida mariogiuffrida force-pushed the CDAP-19300-container-injection-feature branch from 57d0ed0 to 21cf8d0 Compare November 15, 2022 15:49
@mariogiuffrida
Copy link
Author

@arjan-bal @dli357 I have uploaded a new version which considers all your comments (thank you). Could you please review it?

Copy link
Contributor

@dli357 dli357 left a 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 /////
/////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////
Copy link
Contributor

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 /////
///////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////
Copy link
Contributor

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 /////
///////////////////////////////////////////////////////
// /////////////////////////////////////////////////////
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants