Skip to content

Commit

Permalink
Enable use of namespaced broker in healthchecker (kubernetes-retired#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkhahn authored and yangweiwei committed May 10, 2019
1 parent e7e70a1 commit 29ece04
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions charts/healthcheck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Flag | Description
--log_backtrace_at traceLocation | when logging hits line file:N, emit a stack trace (default :0)
--log_dir string | If non-empty, write log files in this directory
--logtostderr | log to standard error instead of files
--namespaced-broker | whether to use a namespaced service broker (default false)
--secure-port int | The port on which to serve HTTPS with authentication and authorization. If 0, don't serve HTTPS at all. (default 443)
--stderrthreshold severity | logs at or above this threshold go to stderr (default 2)
--tls-cert-file string | File containing the default x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). If HTTPS serving is enabled, and --tls-cert-file and --tls-private-key-file are not provided, a self-signed certificate and key are generated for the public address and saved to the directory specified by --cert-dir.
Expand Down
57 changes: 34 additions & 23 deletions cmd/healthcheck/framework/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type HealthCheck struct {
bindingName string
brokerendpointName string
namespace *corev1.Namespace // ns where we create instance and binding
usenamespacedbroker bool
frameworkError error
}

Expand Down Expand Up @@ -173,26 +174,25 @@ func (h *HealthCheck) verifyBrokerIsReady() error {
return h.setError("endpoint not found: %v", err.Error())
}

url := "http://" + h.brokername + "." + h.brokernamespace + ".svc.cluster.local"
broker := &v1beta1.ClusterServiceBroker{
ObjectMeta: metav1.ObjectMeta{
Name: h.brokername,
},
Spec: v1beta1.ClusterServiceBrokerSpec{
CommonServiceBrokerSpec: v1beta1.CommonServiceBrokerSpec{
URL: url,
klog.V(4).Infof("checking for Broker %v to be ready", h.brokername)
if h.usenamespacedbroker {
err = util.WaitForBrokerCondition(h.serviceCatalogClientSet.ServicecatalogV1beta1(),
h.brokername,
v1beta1.ServiceBrokerCondition{
Type: v1beta1.ServiceBrokerConditionReady,
Status: v1beta1.ConditionTrue,
},
},
h.brokernamespace,
)
} else {
err = util.WaitForBrokerCondition(h.serviceCatalogClientSet.ServicecatalogV1beta1(),
h.brokername,
v1beta1.ServiceBrokerCondition{
Type: v1beta1.ServiceBrokerConditionReady,
Status: v1beta1.ConditionTrue,
},
)
}

klog.V(4).Infof("checking for Broker %v to be ready", broker.Name)
err = util.WaitForBrokerCondition(h.serviceCatalogClientSet.ServicecatalogV1beta1(),
broker.Name,
v1beta1.ServiceBrokerCondition{
Type: v1beta1.ServiceBrokerConditionReady,
Status: v1beta1.ConditionTrue,
},
)
if err != nil {
return h.setError("broker not ready: %v", err.Error())
}
Expand All @@ -211,20 +211,30 @@ func (h *HealthCheck) createInstance() error {
return h.frameworkError
}
klog.V(4).Info("Creating a ServiceInstance")
var err error
var planReference v1beta1.PlanReference

if h.usenamespacedbroker {
planReference = v1beta1.PlanReference{
ServiceClassExternalName: h.serviceclassName,
ServicePlanExternalName: "default",
}
} else {
planReference = v1beta1.PlanReference{
ClusterServiceClassExternalName: h.serviceclassName,
ClusterServicePlanExternalName: "default",
}
}
instance := &v1beta1.ServiceInstance{
ObjectMeta: metav1.ObjectMeta{
Name: h.instanceName,
Namespace: h.namespace.Name,
},
Spec: v1beta1.ServiceInstanceSpec{
PlanReference: v1beta1.PlanReference{
ClusterServiceClassExternalName: h.serviceclassName,
ClusterServicePlanExternalName: "default",
},
PlanReference: planReference,
},
}
operationStartTime := time.Now()
var err error
instance, err = h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Create(instance)
if err != nil {
return h.setError("error creating instance: %v", err.Error())
Expand Down Expand Up @@ -400,6 +410,7 @@ func (h *HealthCheck) deleteNamespace() error {
}

func (h *HealthCheck) initBrokerAttributes(s *HealthCheckServer) error {
h.usenamespacedbroker = s.UseNamespacedBroker
switch s.TestBrokerName {
case "ups-broker":
h.brokername = "ups-broker"
Expand Down
2 changes: 2 additions & 0 deletions cmd/healthcheck/framework/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type HealthCheckServer struct {
HealthCheckInterval time.Duration
SecureServingOptions *genericoptions.SecureServingOptions
TestBrokerName string
UseNamespacedBroker bool
}

const (
Expand All @@ -62,5 +63,6 @@ func (s *HealthCheckServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.KubeContext, "kubernetes-context", "", "config context to use for kubernetes. If unset, will use value from 'current-context'")
fs.DurationVar(&s.HealthCheckInterval, "healthcheck-interval", s.HealthCheckInterval, "How frequently the end to end health check should be performed")
fs.StringVar(&s.TestBrokerName, "broker-name", "ups-broker", "Broker Name to test against - can only be ups-broker or osb-stub. You must ensure the specified broker is deployed.")
fs.BoolVar(&s.UseNamespacedBroker, "namespaced-broker", false, "Whether to use a namespaced service broker")
s.SecureServingOptions.AddFlags(fs)
}

0 comments on commit 29ece04

Please sign in to comment.