10000 Fix error of dataservices: mongodb, logme2, search, prometheus by haiderShah-HS · Pull Request #50 · anynines/klutchio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix error of dataservices: mongodb, logme2, search, prometheus #50

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

haiderShah-HS
Copy link

There is currently a bug in the provider-anynines which prevents the status of a service binding from being updated correctly for certain dataservices. As a result, the provider continuously attempts to update the status in a loop.

Affected Dataservices:

  • logme2
  • mongodb
  • prometheus
  • search

@haiderShah-HS haiderShah-HS changed the title Fix error of dataservices: mongodb, logme2, search Fix error of dataservices: mongodb, logme2, search, prometheus Apr 24, 2025
Copy link
Contributor
@abdulhaseeb3 abdulhaseeb3 left a comment

Choose a reason for hiding this comment

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

L

@@ -368,6 +371,16 @@ func getInstanceCredentials(instance osbclient.GetInstanceResponse, sb *v1.Servi
return nil
}

func (c external) parseHostAndPort(input string) (host, port string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment of how this function works, with a expected format string

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -376,14 +389,97 @@ func (c external) initializeConnectionDetails(ctx context.Context, sb *v1.Servic
return err
}

sb.Status.AtProvider.ConnectionDetails.HostURL = string(secret.Data["host"])
sb.Status.AtProvider.ConnectionDetails.Port = string(secret.Data["port"])
var hostURL, port string
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 needed?

Copy link
Author

Choose a reason for hiding this comment

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

done


if strings.Contains(instanceName, "search") {
host, found := secret.Data["host"]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an else condition that the host is not in a recognised format

Copy link
Author

Choose a reason for hiding this comment

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

done

Comment on lines 406 to 412
if found && len(host) >= 0 {
hostURL, port, err = c.parseHostAndPort(string(host))
if err != nil {
return err
}
sb.AddConnectionDetails(hostURL, port)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Author

Choose a reason for hiding this comment

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

done

Comment on lines 415 to 421
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
hostURL, port, err = c.parseHostAndPort(string(host[1 : len(host)-1]))
if err != nil {
return err
}
sb.AddConnectionDetails(hostURL, port)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Author

Choose a reason for hiding this comment

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

done

Comment on lines 424 to 466
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
parsedURL, err := url.Parse(string(host[1 : len(host)-1]))
if err != nil {
return err
}
hostURL, port, err = c.parseHostAndPort(parsedURL.Scheme + "://" + parsedURL.Host)
if err != nil {
return err
}
sb.AddConnectionDetails(hostURL, port)
}
host, found = secret.Data["alertmanager_urls"]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
parsedURL, err := url.Parse(string(host[1 : len(host)-1]))
if err != nil {
return err
}
hostURL, port, err = c.parseHostAndPort(parsedURL.Scheme + "://" + parsedURL.Host)
if err != nil {
return err
}
sb.AddConnectionDetails(hostURL, port)
}
host, found = secret.Data["grafana_urls"]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
parsedURL, err := url.Parse(string(host[1 : len(host)-1]))
if err != nil {
return err
}
hostURL, port, err = c.parseHostAndPort(parsedURL.Scheme + "://" + parsedURL.Host)
if err != nil {
return err
}
sb.AddConnectionDetails(hostURL, port)
}
host, found = secret.Data["graphite_exporters"]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
hostURL = string(string(host[1 : len(host)-1]))
port, found := secret.Data["graphite_exporter_port"]
if found {
sb.AddConnectionDetails(hostURL, string(port))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Author

Choose a reason for hiding this comment

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

done

// Validate status
if sb.Status.AtProvider.ConnectionDetails.HasMissingFields() {
if !sb.ConnectionDetailsIsNotEmpty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

and remove this

Copy link
Author

Choose a reason for hiding this comment

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

done


if strings.Contains(instanceName, "search") {
host, found := secret.Data["host"]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also these conditions and the code inside these conditions are repeating, maybe create a function to make it easier on the eyes

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor
@abdulhaseeb3 abdulhaseeb3 left a comment

Choose a reason for hiding this comment

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

Left feedback


func (c external) extractBracketHost(sb *v1.ServiceBinding, secret map[string][]byte, key string) error {
host, found := secret[key]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
if found && len(host) > 2 && host[0] == '[' && host[len(host)-1] == ']' {

Copy link
Author

Choose a reason for hiding this comment

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

done


func (c external) extractPlainHost(sb *v1.ServiceBinding, secret map[string][]byte, key string) error {
host, found := secret[key]
if found && len(host) >= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if found && len(host) >= 0 {
if found && len(host) > 0 {

Copy link
Author

Choose a reason for hiding this comment

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

done


func (c external) extractPrometheusHost(sb *v1.ServiceBinding, secret map[string][]byte, key string, port string) error {
host, found := secret[key]
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if found && len(host) >= 2 && host[0] == '[' && host[len(host)-1] == ']' {
if found && len(host) > 2 && host[0] == '[' && host[len(host)-1] == ']' {

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -376,12 +446,54 @@ func (c external) initializeConnectionDetails(ctx context.Context, sb *v1.Servic
return err
}

sb.Status.AtProvider.ConnectionDetails.HostURL = string(secret.Data["host"])
sb.Status.AtProvider.ConnectionDetails.Port = string(secret.Data["port"])
instanceName := sb.ObjectMeta.Labels["klutch.io/instance-name"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
instanceName := sb.ObjectMeta.Labels["klutch.io/instance-name"]
instanceType := sb.ObjectMeta.Labels["klutch.io/instance-type"]

Copy link
Author

Choose a reason for hiding this comment

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

done

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.

2 participants
0