-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pretty formatter for ClusterService[Class|Plan] (#1408)
* First example using the log context builder. * No format. * Remote controller logging class, not needed yet. * Fixing cr date. * Adding function documentation. * Kind is always type Kind. * Start of log names. * Add comment for type. * I feel so pretty. Oh so pretty. Pretty log lines. * Move type to it's own file. * Renaming files, fixing receiver names. * Working on an example for Pretty Names for classes that have internal and external names. * Remove old logging file. * Merge. * Finish controller.go. * Fix comment. * finished controller_broker.go as an example. * Fixing unit test.
- Loading branch information
Showing
5 changed files
with
203 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pretty | ||
|
||
// Kind is used for the enum of the Type of object we are building context for. | ||
type Kind int | ||
|
||
// Names of Types to use when creating pretty messages | ||
const ( | ||
Unknown Kind = iota | ||
ClusterServiceClass | ||
ClusterServicePlan | ||
ServiceInstance | ||
) | ||
|
||
func (k Kind) String() string { | ||
switch k { | ||
case ClusterServiceClass: | ||
return "ClusterServiceClass" | ||
case ClusterServicePlan: | ||
return "ClusterServicePlan" | ||
case ServiceInstance: | ||
return "ServiceInstance" | ||
default: | ||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pretty | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" | ||
) | ||
|
||
// Name prints in the form `<Kind> (K8S: <K8S-Name> ExternalName: <External-Name>)` | ||
// kind is required. k8sName and externalName are optional | ||
func Name(kind Kind, k8sName, externalName string) string { | ||
s := fmt.Sprintf("%s", kind) | ||
if k8sName != "" && externalName != "" { | ||
s += fmt.Sprintf(" (K8S: %q ExternalName: %q)", k8sName, externalName) | ||
} else if k8sName != "" { | ||
s += fmt.Sprintf(" (K8S: %q)", k8sName) | ||
} else if externalName != "" { | ||
s += fmt.Sprintf(" (ExternalName: %q)", externalName) | ||
} | ||
return s | ||
} | ||
|
||
// ClusterServiceClassName returns a string with the k8s name and external name if available. | ||
func ClusterServiceClassName(serviceClass *v1beta1.ClusterServiceClass) string { | ||
if serviceClass != nil { | ||
return Name(ClusterServiceClass, serviceClass.Name, serviceClass.Spec.ExternalName) | ||
} | ||
return Name(ClusterServiceClass, "", "") | ||
} | ||
|
||
// ClusterServicePlanName returns a string with the k8s name and external name if available. | ||
func ClusterServicePlanName(servicePlan *v1beta1.ClusterServicePlan) string { | ||
if servicePlan != nil { | ||
return Name(ClusterServicePlan, servicePlan.Name, servicePlan.Spec.ExternalName) | ||
} | ||
return Name(ClusterServicePlan, "", "") | ||
} |
Oops, something went wrong.