Skip to content

Commit d02ac34

Browse files
pmoriekibbles-n-bytes
authored andcommitted
Make logging in admission controllers consistent with controller-manager (#1519)
1 parent 31ae521 commit d02ac34

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

plugin/pkg/admission/broker/authsarcheck/admission.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ func (s *sarcheck) Admit(a admission.Attributes) error {
7474
if a.GetResource().Group != servicecatalog.GroupName || a.GetResource().GroupResource() != servicecatalog.Resource("clusterservicebrokers") {
7575
return nil
7676
}
77-
clusterClusterServiceBroker, ok := a.GetObject().(*servicecatalog.ClusterServiceBroker)
77+
clusterServiceBroker, ok := a.GetObject().(*servicecatalog.ClusterServiceBroker)
7878
if !ok {
7979
return errors.NewBadRequest("Resource was marked with kind ClusterServiceBroker, but was unable to be converted")
8080
}
81-
glog.V(5).Infof("Retrieved clusterClusterServiceBroker %v", clusterClusterServiceBroker)
8281

83-
if clusterClusterServiceBroker.Spec.AuthInfo == nil {
82+
if clusterServiceBroker.Spec.AuthInfo == nil {
8483
// no auth secret to check
8584
return nil
8685
}
8786

8887
var secretRef *servicecatalog.ObjectReference
89-
if clusterClusterServiceBroker.Spec.AuthInfo.Basic != nil {
90-
secretRef = clusterClusterServiceBroker.Spec.AuthInfo.Basic.SecretRef
91-
} else if clusterClusterServiceBroker.Spec.AuthInfo.Bearer != nil {
92-
secretRef = clusterClusterServiceBroker.Spec.AuthInfo.Bearer.SecretRef
88+
if clusterServiceBroker.Spec.AuthInfo.Basic != nil {
89+
secretRef = clusterServiceBroker.Spec.AuthInfo.Basic.SecretRef
90+
} else if clusterServiceBroker.Spec.AuthInfo.Bearer != nil {
91+
secretRef = clusterServiceBroker.Spec.AuthInfo.Bearer.SecretRef
9392
}
93+
glog.V(5).Infof("ClusterServiceBroker %q: evaluating auth secret ref", clusterServiceBroker)
9494
userInfo := a.GetUserInfo()
9595

9696
sar := &authorizationapi.SubjectAccessReview{

plugin/pkg/admission/namespace/lifecycle/admission.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (l *lifecycle) Admit(a admission.Attributes) error {
106106
exists = true
107107
}
108108
if exists {
109-
glog.V(4).Infof("found %s in cache after waiting", a.GetNamespace())
109+
glog.V(4).Infof("found namespace %q in cache after waiting", a.GetNamespace())
110110
}
111111
}
112112

@@ -120,7 +120,7 @@ func (l *lifecycle) Admit(a admission.Attributes) error {
120120
case err != nil:
121121
return errors.NewInternalError(err)
122122
}
123-
glog.V(4).Infof("found %s via storage lookup", a.GetNamespace())
123+
glog.V(4).Infof("found namespace %q via storage lookup", a.GetNamespace())
124124
}
125125

126126
// ensure that we're not trying to create objects in terminating namespaces
@@ -129,7 +129,7 @@ func (l *lifecycle) Admit(a admission.Attributes) error {
129129
return nil
130130
}
131131

132-
return admission.NewForbidden(a, fmt.Errorf("unable to create new content in namespace %s because it is being terminated", a.GetNamespace()))
132+
return admission.NewForbidden(a, fmt.Errorf("unable to create new content in namespace %q because it is being terminated", a.GetNamespace()))
133133
}
134134

135135
return nil

plugin/pkg/admission/servicebindings/lifecycle/admission.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ func (b *enforceNoNewCredentialsForDeletedInstance) Admit(a admission.Attributes
7373

7474
credentials, ok := a.GetObject().(*servicecatalog.ServiceBinding)
7575
if !ok {
76-
return apierrors.NewBadRequest("Resource was marked with kind ServiceBindings but was unable to be converted")
76+
return apierrors.NewBadRequest("Resource was marked with kind ServiceBinding but was unable to be converted")
7777
}
7878

7979
instanceRef := credentials.Spec.ServiceInstanceRef
8080
instance, err := b.instanceLister.ServiceInstances(credentials.Namespace).Get(instanceRef.Name)
8181

8282
// block the credentials operation if the ServiceInstance is being deleted
8383
if err == nil && instance.DeletionTimestamp != nil {
84-
warning := fmt.Sprintf("ServiceBindings %s/%s references an instance that is being deleted: %s/%s",
84+
warning := fmt.Sprintf("ServiceBinding %s/%s references a ServiceInstance that is being deleted: %s/%s",
8585
credentials.Namespace,
8686
credentials.Name,
8787
credentials.Namespace,
@@ -101,7 +101,7 @@ func (b *enforceNoNewCredentialsForDeletedInstance) SetInternalServiceCatalogInf
101101

102102
func (b *enforceNoNewCredentialsForDeletedInstance) Validate() error {
103103
if b.instanceLister == nil {
104-
return fmt.Errorf("missing instanceLister")
104+
return fmt.Errorf("missing serviceInstanceLister")
105105
}
106106
return nil
107107
}

plugin/pkg/admission/servicebindings/lifecycle/admission_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestBlockNewCredentialsForDeletedInstance(t *testing.T) {
100100
if err == nil {
101101
t.Errorf("Unexpected error: %v", err.Error())
102102
} else {
103-
if err.Error() != "servicebindings.servicecatalog.k8s.io \"test-cred\" is forbidden: ServiceBindings test-ns/test-cred references an instance that is being deleted: test-ns/test-instance" {
103+
if err.Error() != "servicebindings.servicecatalog.k8s.io \"test-cred\" is forbidden: ServiceBinding test-ns/test-cred references a ServiceInstance that is being deleted: test-ns/test-instance" {
104104
t.Fatalf("admission controller blocked the request but not with expected error, expected a forbidden error, got %q", err.Error())
105105
}
106106
}

plugin/pkg/admission/serviceplan/defaultserviceplan/admission.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (d *defaultServicePlan) Admit(a admission.Attributes) error {
6868
}
6969
instance, ok := a.GetObject().(*servicecatalog.ServiceInstance)
7070
if !ok {
71-
return apierrors.NewBadRequest("Resource was marked with kind Instance but was unable to be converted")
71+
return apierrors.NewBadRequest("Resource was marked with kind ServiceInstance but was unable to be converted")
7272
}
7373

7474
// If the plan is specified, let it through and have the controller
@@ -83,7 +83,7 @@ func (d *defaultServicePlan) Admit(a admission.Attributes) error {
8383
if !apierrors.IsNotFound(err) {
8484
return admission.NewForbidden(a, err)
8585
}
86-
msg := fmt.Sprintf("ServiceClass %q does not exist, can not figure out the default Service Plan.", instance.Spec.ClusterServiceClassExternalName)
86+
msg := fmt.Sprintf("ClusterServiceClass %q does not exist, can not figure out the default ClusterServicePlan.", instance.Spec.ClusterServiceClassExternalName)
8787
glog.V(4).Info(msg)
8888
return admission.NewForbidden(a, errors.New(msg))
8989
}
@@ -98,30 +98,30 @@ func (d *defaultServicePlan) Admit(a admission.Attributes) error {
9898

9999
plans, err := d.getClusterServicePlansByClusterServiceClassName(sc.Name)
100100
if err != nil {
101-
msg := fmt.Sprintf("Error listing plans for service class (K8S: %v ExternalName: %v) - retry and specify desired ClusterServicePlan", sc.Name, instance.Spec.ClusterServiceClassExternalName)
102-
glog.V(4).Info(msg)
101+
msg := fmt.Sprintf("Error listing ClusterServicePlans for ClusterServiceClass (K8S: %v ExternalName: %v) - retry and specify desired ClusterServicePlan", sc.Name, instance.Spec.ClusterServiceClassExternalName)
102+
glog.V(4).Infof(`ServiceInstance "%s/%s": %s`, instance.Namespace, instance.Name, msg)
103103
return admission.NewForbidden(a, errors.New(msg))
104104
}
105105

106106
// check if there were any service plans
107107
// TODO: in combination with not allowing classes with no plans, this should be impossible
108108
if len(plans) <= 0 {
109-
msg := fmt.Sprintf("no plans found at all for service class %q", instance.Spec.ClusterServiceClassExternalName)
110-
glog.V(4).Info(msg)
109+
msg := fmt.Sprintf("no ClusterServicePlans found at all for ClusterServiceClass %q", instance.Spec.ClusterServiceClassExternalName)
110+
glog.V(4).Infof(`ServiceInstance "%s/%s": %s`, instance.Namespace, instance.Name, msg)
111111
return admission.NewForbidden(a, errors.New(msg))
112112
}
113113

114114
// check if more than one service plan was specified and error
115115
if len(plans) > 1 {
116116
msg := fmt.Sprintf("ServiceClass %q has more than one plan, PlanName must be specified", instance.Spec.ClusterServiceClassExternalName)
117-
glog.V(4).Info(msg)
117+
glog.V(4).Infof(`ServiceInstance "%s/%s": %s`, instance.Namespace, instance.Name, msg)
118118
return admission.NewForbidden(a, errors.New(msg))
119119
}
120120
// otherwise, by default, pick the only plan that exists for the service class
121121

122122
p := plans[0]
123-
glog.V(4).Infof("Using default plan %q (K8S: %q) for Service Class %q for instance %s",
124-
p.Spec.ExternalName, p.Name, sc.Spec.ExternalName, instance.Name)
123+
glog.V(4).Infof(`ServiceInstance "%s/%s": Using default plan %q (K8S: %q) for Service Class %q`,
124+
instance.Namespace, instance.Name, p.Spec.ExternalName, p.Name, sc.Spec.ExternalName)
125125
if instance.Spec.ClusterServiceClassExternalName != "" {
126126
instance.Spec.ClusterServicePlanExternalName = p.Spec.ExternalName
127127
} else {
@@ -147,10 +147,10 @@ func (d *defaultServicePlan) SetInternalServiceCatalogClientSet(f internalclient
147147

148148
func (d *defaultServicePlan) Validate() error {
149149
if d.scClient == nil {
150-
return errors.New("missing service class interface")
150+
return errors.New("missing clusterserviceclass interface")
151151
}
152152
if d.spClient == nil {
153-
return errors.New("missing serviceplan interface")
153+
return errors.New("missing clusterserviceplan interface")
154154
}
155155
return nil
156156
}
@@ -163,27 +163,27 @@ func (d *defaultServicePlan) getClusterServiceClassByPlanReference(a admission.A
163163
}
164164

165165
func (d *defaultServicePlan) getClusterServiceClassByK8SName(a admission.Attributes, scK8SName string) (*servicecatalog.ClusterServiceClass, error) {
166-
glog.V(4).Infof("Fetching serviceclass by class k8s name %q", scK8SName)
166+
glog.V(4).Infof("Fetching ClusterServiceClass by k8s name %q", scK8SName)
167167
return d.scClient.Get(scK8SName, apimachineryv1.GetOptions{})
168168
}
169169

170170
func (d *defaultServicePlan) getClusterServiceClassByExternalName(a admission.Attributes, scName string) (*servicecatalog.ClusterServiceClass, error) {
171-
glog.V(4).Infof("Fetching serviceclass filtered by class external name %q", scName)
171+
glog.V(4).Infof("Fetching ClusterServiceClass filtered by external name %q", scName)
172172
fieldSet := fields.Set{
173173
"spec.externalName": scName,
174174
}
175175
fieldSelector := fields.SelectorFromSet(fieldSet).String()
176176
listOpts := apimachineryv1.ListOptions{FieldSelector: fieldSelector}
177177
serviceClasses, err := d.scClient.List(listOpts)
178178
if err != nil {
179-
glog.V(4).Infof("List failed %q", err)
179+
glog.V(4).Infof("Listing ClusterServiceClasses failed: %q", err)
180180
return nil, err
181181
}
182182
if len(serviceClasses.Items) == 1 {
183-
glog.V(4).Infof("Found Single item as %+v", serviceClasses.Items[0])
183+
glog.V(4).Infof("Found single ClusterServiceClass as %+v", serviceClasses.Items[0])
184184
return &serviceClasses.Items[0], nil
185185
}
186-
msg := fmt.Sprintf("Could not find a single ServiceClass with name %q, found %v", scName, len(serviceClasses.Items))
186+
msg := fmt.Sprintf("Could not find a single ClusterServiceClass with name %q, found %v", scName, len(serviceClasses.Items))
187187
glog.V(4).Info(msg)
188188
return nil, admission.NewNotFound(a)
189189
}
@@ -199,10 +199,10 @@ func (d *defaultServicePlan) getClusterServicePlansByClusterServiceClassName(scN
199199
listOpts := apimachineryv1.ListOptions{FieldSelector: fieldSelector}
200200
servicePlans, err := d.spClient.List(listOpts)
201201
if err != nil {
202-
glog.Infof("List failed %q", err)
202+
glog.Infof("Listing ClusterServicePlans failed: %q", err)
203203
return nil, err
204204
}
205-
glog.V(4).Infof("plans fetched by filtering classname: %+v", servicePlans.Items)
205+
glog.V(4).Infof("ClusterServicePlans fetched by filtering classname: %+v", servicePlans.Items)
206206
r := servicePlans.Items
207207
return r, err
208208
}

0 commit comments

Comments
 (0)