• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / sap-btp-service-operator / 14952372911

11 May 2025 04:41AM UTC coverage: 80.126% (-0.5%) from 80.652%
14952372911

Pull #520

github

I065450
bump libs
Pull Request #520: Bump go version

48 of 52 new or added lines in 6 files covered. (92.31%)

27 existing lines in 3 files now uncovered.

2802 of 3497 relevant lines covered (80.13%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.83
/api/v1/serviceinstance_validating_webhook.go
1
/*
2

3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package v1
18

19
import (
20
        "context"
21
        "fmt"
22
        "strings"
23

24
        "github.com/SAP/sap-btp-service-operator/api/common"
25

26
        "k8s.io/apimachinery/pkg/runtime"
27
        ctrl "sigs.k8s.io/controller-runtime"
28
        logf "sigs.k8s.io/controller-runtime/pkg/log"
29
        "sigs.k8s.io/controller-runtime/pkg/webhook"
30
        "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
31
)
32

33
func (si *ServiceInstance) SetupWebhookWithManager(mgr ctrl.Manager) error {
×
NEW
34
        return ctrl.NewWebhookManagedBy(mgr).For(si).WithValidator(si).Complete()
×
35
}
×
36

37
// +kubebuilder:webhook:verbs=delete;update;create,path=/validate-services-cloud-sap-com-v1-serviceinstance,mutating=false,failurePolicy=fail,groups=services.cloud.sap.com,resources=serviceinstances,versions=v1,name=vserviceinstance.kb.io,sideEffects=None,admissionReviewVersions=v1beta1;v1
38

39
var _ webhook.CustomValidator = &ServiceInstance{}
40

41
// log is for logging in this package.
42
var serviceinstancelog = logf.Log.WithName("serviceinstance-resource")
43

NEW
44
func (si *ServiceInstance) ValidateCreate(_ context.Context, _ runtime.Object) (warnings admission.Warnings, err error) {
×
45
        return nil, nil
×
46
}
×
47

48
func (si *ServiceInstance) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (warnings admission.Warnings, err error) {
1✔
49
        oldInstance := oldObj.(*ServiceInstance)
1✔
50
        newInstance := newObj.(*ServiceInstance)
1✔
51
        serviceinstancelog.Info("validate update", "name", newInstance.ObjectMeta.Name)
1✔
52

1✔
53
        if oldInstance.Spec.BTPAccessCredentialsSecret != newInstance.Spec.BTPAccessCredentialsSecret {
2✔
54
                return nil, fmt.Errorf("changing the btpAccessCredentialsSecret for an existing instance is not allowed")
1✔
55
        }
1✔
56
        return nil, nil
×
57
}
58

59
func (si *ServiceInstance) ValidateDelete(_ context.Context, newObj runtime.Object) (warnings admission.Warnings, err error) {
1✔
60
        newInstance := newObj.(*ServiceInstance)
1✔
61
        serviceinstancelog.Info("validate delete", "name", newInstance.ObjectMeta.Name)
1✔
62
        if newInstance.ObjectMeta.Annotations != nil {
2✔
63
                preventDeletion, ok := newInstance.ObjectMeta.Annotations[common.PreventDeletion]
1✔
64
                if ok && strings.ToLower(preventDeletion) == "true" {
2✔
65
                        return nil, fmt.Errorf("service instance '%s' is marked with \"prevent deletion\"", newInstance.ObjectMeta.Name)
1✔
66
                }
1✔
67
        }
68
        return nil, nil
1✔
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc