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

kubernetes-sigs / kubebuilder / 10361131150

12 Aug 2024 11:52PM CUT coverage: 81.773%. Remained the same
10361131150

Pull #4073

github

web-flow
:seedling: Bump golang.org/x/tools from 0.23.0 to 0.24.0

Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.23.0 to 0.24.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.23.0...v0.24.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4073: :seedling: Bump golang.org/x/tools from 0.23.0 to 0.24.0

2288 of 2798 relevant lines covered (81.77%)

15.57 hits per line

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

45.0
/pkg/plugins/golang/options.go
1
/*
2
Copyright 2022 The Kubernetes Authors.
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 golang
18

19
import (
20
        "path"
21

22
        "sigs.k8s.io/kubebuilder/v4/pkg/config"
23
        "sigs.k8s.io/kubebuilder/v4/pkg/model/resource"
24
)
25

26
var (
27
        coreGroups = map[string]string{
28
                "admission":             "k8s.io",
29
                "admissionregistration": "k8s.io",
30
                "apps":                  "",
31
                "auditregistration":     "k8s.io",
32
                "apiextensions":         "k8s.io",
33
                "authentication":        "k8s.io",
34
                "authorization":         "k8s.io",
35
                "autoscaling":           "",
36
                "batch":                 "",
37
                "certificates":          "k8s.io",
38
                "coordination":          "k8s.io",
39
                "core":                  "",
40
                "events":                "k8s.io",
41
                "extensions":            "",
42
                "imagepolicy":           "k8s.io",
43
                "networking":            "k8s.io",
44
                "node":                  "k8s.io",
45
                "metrics":               "k8s.io",
46
                "policy":                "",
47
                "rbac.authorization":    "k8s.io",
48
                "scheduling":            "k8s.io",
49
                "setting":               "k8s.io",
50
                "storage":               "k8s.io",
51
        }
52
)
53

54
// Options contains the information required to build a new resource.Resource.
55
type Options struct {
56
        // Plural is the resource's kind plural form.
57
        Plural string
58

59
        // Namespaced is true if the resource should be namespaced.
60
        Namespaced bool
61

62
        // Flags that define which parts should be scaffolded
63
        DoAPI        bool
64
        DoController bool
65
        DoDefaulting bool
66
        DoValidation bool
67
        DoConversion bool
68
}
69

70
// UpdateResource updates the provided resource with the options
71
func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
14✔
72
        if opts.Plural != "" {
16✔
73
                res.Plural = opts.Plural
2✔
74
        }
2✔
75

76
        if opts.DoAPI {
14✔
77
                //nolint:staticcheck
×
78
                res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
×
79

×
80
                res.API = &resource.API{
×
81
                        CRDVersion: "v1",
×
82
                        Namespaced: opts.Namespaced,
×
83
                }
×
84

×
85
        }
×
86

87
        if opts.DoController {
16✔
88
                res.Controller = true
2✔
89
        }
2✔
90

91
        if opts.DoDefaulting || opts.DoValidation || opts.DoConversion {
14✔
92
                //nolint:staticcheck
×
93
                res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
×
94

×
95
                res.Webhooks.WebhookVersion = "v1"
×
96
                if opts.DoDefaulting {
×
97
                        res.Webhooks.Defaulting = true
×
98
                }
×
99
                if opts.DoValidation {
×
100
                        res.Webhooks.Validation = true
×
101
                }
×
102
                if opts.DoConversion {
×
103
                        res.Webhooks.Conversion = true
×
104
                }
×
105
        }
106

107
        // domain and path may need to be changed in case we are referring to a builtin core resource:
108
        //  - Check if we are scaffolding the resource now           => project resource
109
        //  - Check if we already scaffolded the resource            => project resource
110
        //  - Check if the resource group is a well-known core group => builtin core resource
111
        //  - In any other case, default to                          => project resource
112
        // TODO: need to support '--resource-pkg-path' flag for specifying resourcePath
113
        if !opts.DoAPI {
28✔
114
                var alreadyHasAPI bool
14✔
115
                loadedRes, err := c.GetResource(res.GVK)
14✔
116
                alreadyHasAPI = err == nil && loadedRes.HasAPI()
14✔
117
                if !alreadyHasAPI {
28✔
118
                        if domain, found := coreGroups[res.Group]; found {
22✔
119
                                res.Domain = domain
8✔
120
                                res.Path = path.Join("k8s.io", "api", res.Group, res.Version)
8✔
121
                        }
8✔
122
                }
123
        }
124
}
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

© 2025 Coveralls, Inc