-
Notifications
You must be signed in to change notification settings - Fork 84
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
Breakup all the Broker Clients into a clients pkg #222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,12 @@ import ( | |
|
||
"github.com/openshift/ansible-service-broker/pkg/apb" | ||
"github.com/openshift/ansible-service-broker/pkg/broker" | ||
"github.com/openshift/ansible-service-broker/pkg/dao" | ||
"github.com/openshift/ansible-service-broker/pkg/clients" | ||
) | ||
|
||
type Config struct { | ||
Registry apb.RegistryConfig | ||
Dao dao.Config | ||
Dao clients.EtcdConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will mean that if we ever want to add some configuration to the dao that is not etcd related we'd have to redo this. dao.Config was easier so we could configure all of the dao. I see how you arrived here since the only configuration items on the dao were etcd related, but it paints in a corner of only being etcd. |
||
Log LogConfig | ||
Openshift apb.ClusterConfig | ||
ConfigFile string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package clients | ||
|
||
import ( | ||
d "github.com/fsouza/go-dockerclient" | ||
|
||
"github.com/coreos/etcd/client" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset" | ||
) | ||
|
||
var Clients struct { | ||
EtcdClient client.Client | ||
KubernetesClient *clientset.Clientset | ||
DockerClient *d.Client | ||
RESTClient rest.Interface | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package clients | ||
|
||
import ( | ||
docker "github.com/fsouza/go-dockerclient" | ||
logging "github.com/op/go-logging" | ||
) | ||
|
||
func NewDocker(log *logging.Logger) error { | ||
dockerClient, err := docker.NewClient(DockerSocket) | ||
if err != nil { | ||
log.Error("Could not load docker client") | ||
return err | ||
} | ||
|
||
Clients.DockerClient = dockerClient | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package clients | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
logging "github.com/op/go-logging" | ||
|
||
"github.com/coreos/etcd/client" | ||
) | ||
|
||
type EtcdConfig struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should remain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
singleton object I think that we just create them during initialization of application with the configuration of the clients. Allows us to error early if something is going to go wrong imo.
wish that at least on comments that told us the order, which could be added.
👍
👍
To me, it looks like a lot of the ABP code is in their own files. and client.go should all be in the new package. I am wondering what methods you were thinking should be left in apb? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eriknelson +1 to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think code that's responsible for the execution of an apb belongs in the RE: the logic that belongs in the apb pkg, it's effectively There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This sounds ok, we need to make sure we test multiple users of the SAME client at the SAME time. Will that work ok? IS it really a 'single' connection? The old way we created a new connection so if there were multiple provisions going on each worker would have their own connection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I also concur with this 👍 |
||
EtcdHost string `yaml:"etcd_host"` | ||
EtcdPort string `yaml:"etcd_port"` | ||
} | ||
|
||
func NewEtcd(config EtcdConfig, log *logging.Logger) error { | ||
// TODO: Config validation | ||
endpoints := []string{etcdEndpoint(config.EtcdHost, config.EtcdPort)} | ||
|
||
log.Info("== ETCD CX ==") | ||
log.Infof("EtcdHost: %s", config.EtcdHost) | ||
log.Infof("EtcdPort: %s", config.EtcdPort) | ||
log.Infof("Endpoints: %v", endpoints) | ||
|
||
etcdClient, err := client.New(client.Config{ | ||
Endpoints: endpoints, | ||
Transport: client.DefaultTransport, | ||
HeaderTimeoutPerRequest: time.Second, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
Clients.EtcdClient = etcdClient | ||
return nil | ||
} | ||
|
||
func etcdEndpoint(host string, port string) string { | ||
return fmt.Sprintf("http://%s:%s", host, port) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package clients | ||
|
||
import ( | ||
logging "github.com/op/go-logging" | ||
restclient "k8s.io/client-go/rest" | ||
|
||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/util/homedir" | ||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset" | ||
) | ||
|
||
func createClientConfigFromFile(configPath string) (*restclient.Config, error) { | ||
clientConfig, err := clientcmd.LoadFromFile(configPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config, err := clientcmd.NewDefaultClientConfig(*clientConfig, &clientcmd.ConfigOverrides{}).ClientConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return config, nil | ||
} | ||
|
||
func NewKubernetes(log *logging.Logger) error { | ||
// NOTE: Both the external and internal client object are using the same | ||
// clientset library. Internal clientset normally uses a different | ||
// library | ||
clientConfig, err := restclient.InClusterConfig() | ||
if err != nil { | ||
log.Warning("Failed to create a InternalClientSet: %v.", err) | ||
|
||
log.Debug("Checking for a local Cluster Config") | ||
clientConfig, err = createClientConfigFromFile(homedir.HomeDir() + "/.kube/config") | ||
if err != nil { | ||
log.Error("Failed to create LocalClientSet") | ||
return err | ||
} | ||
} | ||
|
||
clientset, err := clientset.NewForConfig(clientConfig) | ||
if err != nil { | ||
log.Error("Failed to create LocalClientSet") | ||
return err | ||
} | ||
|
||
rest := clientset.CoreV1().RESTClient() | ||
|
||
Clients.RESTClient = rest | ||
Clients.KubernetesClient = clientset | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package clients | ||
|
||
const ( | ||
DockerSocket = "unix:///var/run/docker.sock" | ||
) |
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.
Can we push this into the clients package? I think it makes more sense there. Related to my overall comment on apb/client.go
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.
@eriknelson I agree, but this is a much larger change since Client is a class. So things like RunImage need to be distributed out of client.go. For now, I'm going to keep this in place, but adding a TODO in the final patch for this series and we can return to it later.
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.
@rthallisey since I'm requesting the change, mind if I take a crack at it and submit for your review? Think I could probably just explain myself better with code anyways. I think it's totally fine to accept this PR without it and add the TODO for a follow up PR.
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.
@eriknelson That would be fantastic 👍