-
Notifications
You must be signed in to change notification settings - Fork 117
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
Get elastic-agent-managed-daemonset.yaml from upstream 7.x instead of using a local static file #452
Get elastic-agent-managed-daemonset.yaml from upstream 7.x instead of using a local static file #452
Conversation
… using a local static file
Pinging @elastic/integrations (Team:Integrations) |
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪 |
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.
While I was reviewing this draft, I found a potential issue. This file will be downloaded during the installation procedure and be left there forever. If the remote file changes (new commits in 7.x), the elastic-package won't pick it up.
Also, the installation procedure doesn't require internet access so far, so this would be blocking. I think we should consider an alternative approach:
- Remove all local
elastic-agent.yaml
definitions. - Replace the logic which uses local file with one downloading from remote location every time (you can also use the cache directory in
~/.elastic-package/cache
).
internal/install/install.go
Outdated
@@ -238,3 +246,20 @@ func createServiceLogsDir(elasticPackagePath *locations.LocationManager) error { | |||
} | |||
return nil | |||
} | |||
|
|||
// DownloadFile will download a url from a path and return the response body as a string. | |||
func DownloadFile(filepath string, url string) (string, error) { |
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: does it have to be exposed?
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.
no!
internal/install/install.go
Outdated
@@ -184,9 +187,14 @@ func writeKubernetesDeployerResources(elasticPackagePath *locations.LocationMana | |||
return errors.Wrap(err, "can't read application configuration") | |||
} | |||
|
|||
elasticAgentManagedYaml, err := DownloadFile("elastic-agent-managed-kubernetes.yaml", elasticAgentManagedYamlUrl) |
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.
I don't think that filepath
is needed here.
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.
😔 it is not
internal/install/install.go
Outdated
@@ -184,9 +187,14 @@ func writeKubernetesDeployerResources(elasticPackagePath *locations.LocationMana | |||
return errors.Wrap(err, "can't read application configuration") | |||
} | |||
|
|||
elasticAgentManagedYaml, err := DownloadFile("elastic-agent-managed-kubernetes.yaml", elasticAgentManagedYamlUrl) | |||
if err != nil { | |||
return errors.Wrap(err, "downloading elastic-agent-managed-kubernetes.yaml failed") |
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.
I would replace the filename with something abstract in case the filename changes.
internal/install/install.go
Outdated
// Get the data | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return "", err |
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.
Please use the errors.Wrap
to stick some context here.
internal/install/install.go
Outdated
// Convert to string | ||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", err |
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.
same here
internal/install/install.go
Outdated
@@ -184,9 +187,14 @@ func writeKubernetesDeployerResources(elasticPackagePath *locations.LocationMana | |||
return errors.Wrap(err, "can't read application configuration") | |||
} | |||
|
|||
elasticAgentManagedYaml, err := DownloadFile("elastic-agent-managed-kubernetes.yaml", elasticAgentManagedYamlUrl) |
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.
WDYT to replace this function with less generic one like downloadElasticAgentManagedYAML()
? I don't think we need generic DownloadFile
function here.
Great to see this happening! It will help us eliminate issues when changes are happening on Beats/Agent regarding the deployment model/roles etc.
Why the file will stay there forever? I would expect a "download&replace" approach to work here. Or to be more consistent before downloading the deployer can try to |
No, it's a different pattern. Logic behind
That's why I suggested to use this approach. We can download the YAML file in runtime and cache it locally if necessary. |
internal/kubectl/kubectl_apply.go
Outdated
@@ -84,6 +84,22 @@ func Apply(definitionPaths ...string) error { | |||
return nil | |||
} | |||
|
|||
// ApplyStdin function adds resources to the Kubernetes cluster based on provided stdin. | |||
func ApplyStdin(input string) error { | |||
logger.Debugf("Apply Kubernetes definitions") |
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: ... from stdin.
internal/kubectl/kubectl_apply.go
Outdated
logger.Debugf("Apply Kubernetes definitions") | ||
out, err := applyKubernetesResourcesStdin(input) | ||
if err != nil { | ||
return errors.Wrap(err, "can't modify Kubernetes resources (apply)") |
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: ... apply from stdin
"strings" | ||
|
||
"github.com/elastic/elastic-package/internal/install" |
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: please sort this line (put it together with other internal
} | ||
// Replace fleet url | ||
elasticAgentManagedYaml = strings.ReplaceAll(elasticAgentManagedYaml, | ||
"https://fleet-server:8220", |
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 wonder if we should replace it with regexp in case somebody modifies it:
http(s){0,1}://fleet-server:(\d+)
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 is a valid concern. I will change it
@@ -7,3 +7,7 @@ | |||
- name: service.type | |||
type: keyword | |||
description: Service type | |||
- name: orchestrator.cluster.name |
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.
To enable dependency management here, you need to include build.yaml file.
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.
So I will just add this file
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.
You need to format it with elastic-package format
:
[2021-07-30T13:08:28.902Z] Error: checking package failed: formatting the integration failed (path: /var/lib/jenkins/workspace/t-manager_elastic-package_PR-452/src/github.com/elastic/elastic-package/test/packages/kubernetes, failFast: true): walking through the integration files failed: formatting file failed (path: /var/lib/jenkins/workspace/t-manager_elastic-package_PR-452/src/github.com/elastic/elastic-package/test/packages/kubernetes/_dev/build/build.yml): file is not formatted (path: /var/lib/jenkins/workspace/t-manager_elastic-package_PR-452/src/github.com/elastic/elastic-package/test/packages/kubernetes/_dev/build/build.yml)
if err != nil { | ||
return "", errors.Wrap(err, "can't read application configuration") | ||
} | ||
elasticAgentManagedYaml, err := downloadElasticAgentManagedYAML(elasticAgentManagedYamlURL) |
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: YAML comes as bytes. Did you check if we can skip converting to string? It seems that byte-body will fit well here.
if err != nil { | ||
return "", errors.Wrap(err, "can't read application configuration") | ||
} | ||
elasticAgentManagedYaml, err := downloadElasticAgentManagedYAML(elasticAgentManagedYamlURL) |
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: please add a logger debug indicating the download from upstream
internal/kubectl/kubectl_apply.go
Outdated
logger.Debugf("Apply Kubernetes stdin") | ||
out, err := applyKubernetesResourcesStdin(input) | ||
if err != nil { | ||
return errors.Wrap(err, "can't modify Kubernetes resources (apply from stdin)") |
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 you're right in L89, "apply stdin"
} | ||
|
||
err = kubectl.Apply(locationManager.KubernetesDeployerAgentYml()) |
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: logger debug: downloaded N bytes
defer resp.Body.Close() | ||
|
||
// Convert to string | ||
b, err := io.ReadAll(resp.Body) |
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.
is it necessary to go with string?
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.
It is not necessary. I did that in order to use it later in Regexp ReplaceAllString
.
But I can instead use ReplaceAll
that takes a slice of bytes as input.
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.
But I can instead use ReplaceAll that takes a slice of bytes as input.
Sounds good to me
// Get the data | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return "", errors.Wrapf(err, "failed to get file from url %s", url) |
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: from URL
internal/kubectl/kubectl.go
Outdated
@@ -49,3 +50,21 @@ func modifyKubernetesResources(action string, definitionPaths ...string) ([]byte | |||
} | |||
return output, nil | |||
} | |||
|
|||
// applyKubernetesResourcesStdin applies a kubernetes manifest provided as stdin. |
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: a Kubernetes manifest
….com:MichaelKatsoulis/elastic-package into use_upstream_manifest_to_deploy_agent_on_k8s
|
||
// getElasticAgentYaml retrieves elastic-agent-managed.yaml from upstream and modifies the file as needed | ||
// to run locally. | ||
func getElasticAgentYaml() ([]byte, error) { |
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: ...YAML()
…fest_to_deploy_agent_on_k8s
@MichaelKatsoulis Ship it, please. |
This PR aims to close #328.
There is no need anymore for maintaining a static go file for elastic-agent-managed deployment.
Instead the upstream manifest (which creates a Daemonset) can be used. manifest
It is still in draft mode due to one dependancy.