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

kubernetes-sigs / kubebuilder / 14310444848

07 Apr 2025 01:23PM CUT coverage: 71.57%. First build
14310444848

Pull #4766

github

chethanm99
docs: Fix typos and regenerate samples

Corrects various typographical errors in documentation source files and code comments.

Runs 'make generate-docs' to ensure generated documentation, tutorials, and sample project files reflect the corrections and are up-to-date. Addresses generation script conflicts caused by specific typo fixes.
Pull Request #4766: docs: Fix typos and regenerate samples

2311 of 3229 relevant lines covered (71.57%)

16.53 hits per line

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

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

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

57
        // ExternalAPIPath allows to inform a path for APIs not defined in the project
58
        ExternalAPIPath string
59

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

64
        // Namespaced is true if the resource should be namespaced.
65
        Namespaced bool
66

67
        // Flags that define which parts should be scaffolded
68
        DoAPI        bool
69
        DoController bool
70
        DoDefaulting bool
71
        DoValidation bool
72
        DoConversion bool
73

74
        // Spoke versions for conversion webhook
75
        Spoke []string
76
}
77

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

84
        if opts.DoAPI {
14✔
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
        if opts.DoController {
16✔
94
                res.Controller = true
2✔
95
        }
2✔
96

97
        if opts.DoDefaulting || opts.DoValidation || opts.DoConversion {
14✔
98
                res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
×
99

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

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

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