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

kubernetes-sigs / kubebuilder / 11600150636

30 Oct 2024 07:18PM CUT coverage: 75.107%. Remained the same
11600150636

Pull #4258

github

web-flow
:seedling: Bump k8s.io/api in /testdata/project-v4-multigroup

Bumps [k8s.io/api](https://github.com/kubernetes/api) from 0.31.1 to 0.31.2.
- [Commits](https://github.com/kubernetes/api/compare/v0.31.1...v0.31.2)

---
updated-dependencies:
- dependency-name: k8s.io/api
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4258: :seedling: Bump k8s.io/api from 0.31.1 to 0.31.2 in /testdata/project-v4-multigroup

2287 of 3045 relevant lines covered (75.11%)

14.44 hits per line

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

46.94
/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
        // ExternalAPIPath allows to inform a path for APIs not defined in the project
60
        ExternalAPIPath string
61

62
        // ExternalAPIPath allows to inform the resource domain to build the Qualified Group
63
        // to generate the RBAC markers
64
        ExternalAPIDomain string
65

66
        // Namespaced is true if the resource should be namespaced.
67
        Namespaced bool
68

69
        // Flags that define which parts should be scaffolded
70
        DoAPI        bool
71
        DoController bool
72
        DoDefaulting bool
73
        DoValidation bool
74
        DoConversion bool
75
}
76

77
// UpdateResource updates the provided resource with the options
78
func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
14✔
79
        if opts.Plural != "" {
16✔
80
                res.Plural = opts.Plural
2✔
81
        }
2✔
82

83
        if opts.DoAPI {
14✔
84
                //nolint:staticcheck
×
85
                res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
×
86

×
87
                res.API = &resource.API{
×
88
                        CRDVersion: "v1",
×
89
                        Namespaced: opts.Namespaced,
×
90
                }
×
91

×
92
        }
×
93

94
        if opts.DoController {
16✔
95
                res.Controller = true
2✔
96
        }
2✔
97

98
        if opts.DoDefaulting || opts.DoValidation || opts.DoConversion {
14✔
99
                //nolint:staticcheck
×
100
                res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
×
101

×
102
                res.Webhooks.WebhookVersion = "v1"
×
103
                if opts.DoDefaulting {
×
104
                        res.Webhooks.Defaulting = true
×
105
                }
×
106
                if opts.DoValidation {
×
107
                        res.Webhooks.Validation = true
×
108
                }
×
109
                if opts.DoConversion {
×
110
                        res.Webhooks.Conversion = true
×
111
                }
×
112
        }
113

114
        if len(opts.ExternalAPIPath) > 0 {
14✔
115
                res.External = true
×
116
        }
×
117

118
        // domain and path may need to be changed in case we are referring to a builtin core resource:
119
        //  - Check if we are scaffolding the resource now           => project resource
120
        //  - Check if we already scaffolded the resource            => project resource
121
        //  - Check if the resource group is a well-known core group => builtin core resource
122
        //  - In any other case, default to                          => project resource
123
        if !opts.DoAPI {
28✔
124
                var alreadyHasAPI bool
14✔
125
                loadedRes, err := c.GetResource(res.GVK)
14✔
126
                alreadyHasAPI = err == nil && loadedRes.HasAPI()
14✔
127
                if !alreadyHasAPI {
28✔
128
                        if res.External {
14✔
129
                                res.Path = opts.ExternalAPIPath
×
130
                                res.Domain = opts.ExternalAPIDomain
×
131
                        } else {
14✔
132
                                // Handle core types
14✔
133
                                if domain, found := coreGroups[res.Group]; found {
22✔
134
                                        res.Core = true
8✔
135
                                        res.Domain = domain
8✔
136
                                        res.Path = path.Join("k8s.io", "api", res.Group, res.Version)
8✔
137
                                }
8✔
138
                        }
139
                }
140
        }
141
}
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