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

Config impl #567

Merged
merged 9 commits into from Dec 6, 2017
Merged

Config impl #567

merged 9 commits into from Dec 6, 2017

Conversation

shawn-hurley
Copy link
Contributor

Describe what this PR does and why we need it:
Implementation of the config proposal
Changes proposed in this pull request

  • To many to list. Redoing the entire config management

@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 21, 2017
@shawn-hurley shawn-hurley added do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. feature needs-review tech-debt labels Nov 21, 2017
@shawn-hurley
Copy link
Contributor Author

@eriknelson @jmrodri @rthallisey @djzager Some testing help would be nice, this touches so much stuff, that I will forget something during my testing. Things that I am most worried about

  1. Does this seem to make it actually more complicated to add config values?
  2. Make sure there are no inconsistencies in the initialization of config files. I would like a create one way of doing it and stick with that. Here is why I am thinking it should be the responsibility of the package to create its config.
  • The package knows about its changes and can also add validation/defaults at that point.
  • We don't want app to interact with any other package then log and config, to facilitate the logging changes in its proposal.
  1. The secrets config section might not work.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 10f60ec on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

coveralls commented Nov 21, 2017

Coverage Status

Changes Unknown when pulling 3694e65 on shawn-hurley:config-impl into ** on openshift:master**.

@@ -124,7 +124,7 @@ func (s *ServiceAccountManager) CreateApbSandbox(

func (s *ServiceAccountManager) createResources(rFilePath string, namespace string) error {
s.log.Debug("Creating resources from file at path: %s", rFilePath)
output, err := runtime.RunCommand("oc", "create", "-f", rFilePath)
output, err := runtime.RunCommand("oc", "create", "--namespace", namespace, "-f", rFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this namespace meant to be here or is it from another commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another commit, I can remove.

@@ -221,7 +221,7 @@ func (s *ServiceAccountManager) createFile(handle string) (string, error) {
}

// DestroyApbSandbox - Destroys the apb sandbox
func (s *ServiceAccountManager) DestroyApbSandbox(executionContext ExecutionContext, clusterConfig ClusterConfig) {
func (s *ServiceAccountManager) DestroyApbSandbox(executionContext ExecutionContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the removal of the clusterConfig ClusterConfig parameters.

CertFile: config.Broker.SSLCert,
KeyFile: config.Broker.SSLCertKey,
CertFile: config.GetString("broker.ssl_cert"),
KeyFile: config.GetString("broker.ssl_cert_key"),
Copy link
Contributor

Choose a reason for hiding this comment

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

So config.Broker.SSLCert gave us the compile time benefit. But it was also the source of what made adding stuff to the config painful. I would have to go update the struct vs just adding values to the config. Most projects I've worked with I've used the GetString type methods.

@@ -199,11 +201,11 @@ func CreateApp() App {
}

app.log.Debug("Connecting Registry")
for _, r := range app.config.Registry {
reg, err := registries.NewRegistry(r, app.log.Logger)
for name := range app.config.GetSubConfig("registry").ToMap() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The GetSubConfig is also acceptable.

@shawn-hurley shawn-hurley removed the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Nov 27, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f2ec97f on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

coveralls commented Nov 27, 2017

Coverage Status

Changes Unknown when pulling f2ec97f on shawn-hurley:config-impl into ** on openshift:master**.

WhiteList: con.GetSliceOfStrings("white_list"),
BlackList: con.GetSliceOfStrings("black_list"),
AuthType: con.GetString("auth_type"),
AuthName: con.GetString("auth_name"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the thing you mentioned to me where we can have the config struct which gives me compile time validation while using the config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmrodri yes, another example is the broker config in the AnsibleBroker struct.

I think if we move to an Interface & Struct to the APB package, then this is a pattern that we can follow there.

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

CONDACK pending answers to my questions.

@@ -103,27 +104,29 @@ func match(spec *Spec, rule AssociationRule) bool {

// InitializeSecretsCache - Generates AssociationRules from config and
// initializes the global secrets cache
func InitializeSecretsCache(config []SecretsConfig, log *logging.Logger) {
func InitializeSecretsCache(con *config.Config, log *logging.Logger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about conf instead of con

var (
log = logging.MustGetLogger("config")
)

Copy link
Contributor

Choose a reason for hiding this comment

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

There might be an easier way to share the config data.

// pkg/config/broker.go
client.NewConfig(...)


// pkg/config/config.go
var configFile map[string]interface{}

func NewConfig(conf map[string]interface{}) error {
       ...
       configFile = conf
       return nil
}

func GetConfigValue(value string) (string, error) {
       ....
       return configFile[value], nil
}

Then every pkg can have access to the var through the GetConfigValue function. If there's nested config values we could also add a GetNestedConfigValue.

config.GetConfigValue(configValue)

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 6540b2c on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 81c30a6 on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling af9d7e0 on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 9bb233d on shawn-hurley:config-impl into ** on openshift:master**.

Copy link
Contributor

@eriknelson eriknelson left a comment

Choose a reason for hiding this comment

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

CONDACK

Few questions just curious about, otherwise I think this is a big improvement. Especially happy to get rid of config references in every fn sig 👍

One thought that comes to mind is that it will be very easy to fat finger a config value lookup string. It's maybe less of a problem with some types, but often we may take two very different behavioral branches depending on a config value. I can see us taking a falsy branch here unintentionally with just a debug log to indicate what actually happened.

Maybe we want to kick those up to warning level logs? Not sure I have a better option to offer here, but kind of curious what other people think.

Overall, nice job @shawn-hurley !

}

err := broker.Login()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we able to get rid of all of this? Looking this over again, I'm not a fan of this being in a New* method, so I'm a proponent of pulling it out, but I want to make sure this isn't a regression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are able to get rid of this because the initialization of the clients does the things that we need. I think this code has not been needed for a long time. I can add it back if people don't want it removed in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be better to add it back and remove in an explicit PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eriknelson I just realized while adding it back why I removed it. I removed the clusterConfig from the broker object causing this to be a problem where it is with this PR.

I did not add it back because this will just initialize the OC client, while everything should no longer be using the local oc client.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've been commenting this out locally for a few days now because it messes up the local k8s deployment. I don't think we need it anymore. Removing it will also be one less thing we need to add to the runtime pkg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we also be removing the Config Values as well (Host and BearerTokenFile)

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know of folks wanting to use their own bearer tokens instead of using auth that k8s provides? To me, I think it would be safe to remove it. We could always add it back in later if that is a valid use case.

}

// GetEtcdVersion - Connects to ETCD cluster and retrieves server/version info
func GetEtcdVersion(ec EtcdConfig) (string, string, error) {
// The next etcd release (1.4) will have client.GetVersion()
// We'll use this to test our etcd connection for now
etcdURL := fmt.Sprintf("http://%s:%s/version", ec.EtcdHost, ec.EtcdPort)
etcdURL := fmt.Sprintf("http://%s:%v/version", ec.EtcdHost, ec.EtcdPort)
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own edification, what's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EtcdPort was changed to an int, %s assumes a string, %v is just the value of the thing so works for everything. https://golang.org/pkg/fmt/ if you want to see all the options that fmt gives you.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8c27f14 on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 31e9156 on shawn-hurley:config-impl into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 08dc5a8 on shawn-hurley:config-impl into ** on openshift:master**.

@rthallisey rthallisey merged commit 14e5177 into openshift:master Dec 6, 2017
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
* adding configuration package

* changing everyting for configuration changes

* fixing test handler.

* rebase changes.

* fixing tests

* fixing variable name from review comments

* fixing logging debug statements that were left over.

* removing Host, CAFILE, and BearerToken as they are no longer used.

* fixing rebase of app.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature needs-review size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tech-debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants