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

Do not bring up the PostgreSQL or Kafka/Zookeeper services if specifying external services #604

Merged
merged 2 commits into from
Aug 18, 2020

Conversation

abellotti
Copy link
Member

@abellotti abellotti commented Aug 4, 2020

Do not bring up:

  • the PostgreSQL service if the user is using their own external PostgreSQL server and
    they specified the postgresql secret with the external PostgreSQL hostname defined there.
  • the Kafka and Zookeeper service if the user specified a Kafka secret with a Kafka messaging
    service hostname defined.

Fixes: #529

postgresql secret and defined an external postgresql server hostname.
@chessbyte
Copy link
Member

I see this pattern over and over in our operator. Is it possible to make a method/function in Go to abstract this?

@abellotti
Copy link
Member Author

Are you talking about the new code added or the following pattern ?

if e := r.generatePostgresqlResources(miqInstance); e != nil {
			return reconcile.Result{}, e

For the latter, I'd keep those as it's the go pattern for error check/propagation up. For the new code added, I agree, I'd like to generalize it if possible, I'll work on the kafka side and see if we can use common code for secret checks and such.

@Fryguy
Copy link
Member

Fryguy commented Aug 7, 2020

@abellotti How are you distinguishing an external postgres vs an internal postgres where we've autocreated the secret...is it the hostname being blank?

@abellotti
Copy link
Member Author

Yes, a user must have provided a secret with a non-blank hostname.

@abellotti abellotti changed the title [WIP] Do not bring up the PostgreSQL service if using an external PostgreSQL server database [WIP] Do not bring up the PostgreSQL or Kafka/Zookeeper services if specifying external services Aug 7, 2020
and leveraged the same to also skip kafka/zookeeper
deployment if kafka secret and hostname were specified.
@miq-bot
Copy link
Member

miq-bot commented Aug 7, 2020

Checked commits abellotti/manageiq-pods@3c22858~...7cd301d with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.28.0, and yamllint
0 files checked, 0 offenses detected
Everything looks fine. 🍪

@abellotti
Copy link
Member Author

Keeping as WIP for now as it needs some more testing.

@abellotti
Copy link
Member Author

Successfully tested using an external Kafka server after having fun with #607 (comment) - unwipping.

@abellotti abellotti changed the title [WIP] Do not bring up the PostgreSQL or Kafka/Zookeeper services if specifying external services Do not bring up the PostgreSQL or Kafka/Zookeeper services if specifying external services Aug 12, 2020
@abellotti abellotti removed the wip label Aug 12, 2020
@Fryguy
Copy link
Member

Fryguy commented Aug 18, 2020

Yes, a user must have provided a secret with a non-blank hostname.

But what does the generated secret look like? If it also has a hostname, then you can't tell them apart after the fact.

@@ -439,3 +451,13 @@ func (r *ReconcileManageIQ) createk8sResIfNotExist(cr *miqv1alpha1.ManageIQ, res
}
return nil
}

func getSecretKeyValue(client client.Client, nameSpace string, secretName string, keyName string) string {
Copy link
Member

Choose a reason for hiding this comment

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

I think there's another file with secret methods, where this might belong better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I saw, pod specific helpers (postgres, kafka, etc) to return the default secret name and default secret if not specified. One possibility is to try to move this to pkg/helpers/miq-components/util.go

Copy link
Member

Choose a reason for hiding this comment

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

I don't see a better place for this right now.

@@ -439,3 +451,13 @@ func (r *ReconcileManageIQ) createk8sResIfNotExist(cr *miqv1alpha1.ManageIQ, res
}
return nil
}

func getSecretKeyValue(client client.Client, nameSpace string, secretName string, keyName string) string {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a better place for this right now.

@bdunne bdunne merged commit 45d83cd into ManageIQ:master Aug 18, 2020
@@ -267,6 +267,12 @@ func (r *ReconcileManageIQ) generateMemcachedResources(cr *miqv1alpha1.ManageIQ)
}

func (r *ReconcileManageIQ) generatePostgresqlResources(cr *miqv1alpha1.ManageIQ) error {
hostName := getSecretKeyValue(r.client, cr.Namespace, cr.Spec.DatabaseSecret, "hostname")
if hostName != "" {
Copy link
Member

Choose a reason for hiding this comment

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

@abellotti Should this be if hostName != "postgresql" {?

Copy link
Member

Choose a reason for hiding this comment

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

No, this is what triggers external vs internal - #604 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

It's not obvious to me why this would be empty string since either the user creates the secret with a hostname or we do...

Copy link
Member Author

Choose a reason for hiding this comment

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

It should stay if hostName != "", if the user specified a secret with a non-blank hostname we're done, we don't get to call that DefaultPostgresqlSecret (where we populate the secret for the local postgresql case), which is called on line 276 after the if clause.

Copy link
Member

@Fryguy Fryguy Feb 2, 2021

Choose a reason for hiding this comment

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

@bdunne Yeah I had the same question - I assumed when we generate it ourselves we don't specify a hostname?

#604 (comment)

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

Successfully merging this pull request may close these issues.

Don't deploy the database/kafka if the user provides the corresponding secret
5 participants