Skip to content

Commit fdbecee

Browse files
kamiiiela-cordier
authored andcommitted
refactor: update kubectl error and warnings
1 parent cbb9e82 commit fdbecee

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

api/v1alpha1/apiv4definition_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func validateApi(api *ApiV4Definition) (admission.Warnings, error) {
5858
if api.HasContext() {
5959
mCtx := new(ManagementContext)
6060
if err := k8s.GetClient().Get(context.Background(), api.ContextRef().NamespacedName(), mCtx); err != nil {
61-
return admission.Warnings{}, fmt.Errorf("can't create api [%s] because it is using "+
61+
return admission.Warnings{}, fmt.Errorf("can't create API [%s] because it is using "+
6262
"management context [%v] that doesn't exist in the cluster", api.Name, api.ContextRef().NamespacedName())
6363
}
6464
} else {
@@ -132,7 +132,7 @@ func findDuplicatePath(existingPaths []string, newPaths []string) error {
132132
for _, ep := range existingPaths {
133133
for _, np := range newPaths {
134134
if ep == np {
135-
return fmt.Errorf("invalid api context path. the same path already exist [%s]", ep)
135+
return fmt.Errorf("invalid API context path [%s]. Another API with the same path already exists", ep)
136136
}
137137
}
138138
}

api/v1alpha1/managementcontext_webhook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func validateManagementContext(ctx *ManagementContext) (admission.Warnings, erro
6262
secret := new(corev1.Secret)
6363
err := k8s.GetClient().Get(context.Background(), ctx.Spec.SecretRef().NamespacedName(), secret)
6464
if err != nil {
65-
return admission.Warnings{}, errors.Wrap(err, fmt.Sprintf("can't create management context because it is using "+
66-
"sercret [%v] that doesn't exist in the cluster", ctx.Spec.SecretRef()))
65+
return admission.Warnings{}, fmt.Errorf("can't create management context [%s] because it is using "+
66+
"sercret [%v] that doesn't exist in the cluster", ctx.Name, ctx.Spec.SecretRef())
6767
}
6868
}
6969

@@ -88,7 +88,7 @@ func checkAPIAvailability(ctx *ManagementContext) error {
8888

8989
var opError *net.OpError
9090
if errors.As(err, &opError) {
91-
return err
91+
return fmt.Errorf("unable to reach APIM, [%s] is not available", ctx.Spec.BaseUrl)
9292
}
9393

9494
return nil

0 commit comments

Comments
 (0)