Skip to content

Commit 6db0dc8

Browse files
committed
⚠️ Enforce comments on most of the codebase
Marked as a breaking change because we're unexporting some previously exported variables or structs. Signed-off-by: Vince Prignano <[email protected]>
1 parent fa1cee5 commit 6db0dc8

File tree

64 files changed

+169
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+169
-21
lines changed

.golangci.yml

+15-6
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,32 @@ issues:
4444
exclude:
4545
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
4646
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
47-
- exported method `.*.Reconcile` should have comment or be unexported
48-
- exported method `.*.SetupWithManager` should have comment or be unexported
47+
- exported method `.*.(Reconcile|SetupWithManager|SetupWebhookWithManager)` should have comment or be unexported
4948
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
5049
# If it is decided they will not be addressed they should be moved above this comment.
5150
- Subprocess launch(ed with variable|ing should be audited)
5251
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
5352
- (G104|G307)
54-
- exported (method|function|type|const) (.+) should have comment or be unexported
5553
exclude-rules:
5654
# With Go 1.16, the new embed directive can be used with an un-named import,
5755
# golint only allows these to be imported in a main.go, which wouldn't work for us.
5856
# This directive allows the embed package to be imported with an underscore everywhere.
5957
- linters:
6058
- golint
6159
source: _ "embed"
60+
# Exclude some packages or code to require comments, for example test code, or fake clients.
61+
- linters:
62+
- golint
63+
text: exported (method|function|type|const) (.+) should have comment or be unexported
64+
source: (func|type).*Fake.*
65+
- linters:
66+
- golint
67+
text: exported (method|function|type|const) (.+) should have comment or be unexported
68+
path: fake_\.go
69+
- linters:
70+
- golint
71+
text: exported (method|function|type|const) (.+) should have comment or be unexported
72+
path: .*test/(providers|framework|e2e).*.go
6273
# Disable unparam "always receives" which might not be really
6374
# useful when building libraries.
6475
- linters:
@@ -70,9 +81,7 @@ issues:
7081
text: should not use dot imports
7182
- path: _test\.go
7283
text: cyclomatic complexity
73-
- path: test/framework.*.go
74-
text: should not use dot imports
75-
- path: test/e2e.*.go
84+
- path: test/(framework|e2e).*.go
7685
text: should not use dot imports
7786

7887
run:

api/v1alpha3/cluster_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ type Cluster struct {
213213
Status ClusterStatus `json:"status,omitempty"`
214214
}
215215

216+
// GetConditions returns the set of conditions for this object.
216217
func (c *Cluster) GetConditions() Conditions {
217218
return c.Status.Conditions
218219
}
219220

221+
// SetConditions sets the conditions on this object.
220222
func (c *Cluster) SetConditions(conditions Conditions) {
221223
c.Status.Conditions = conditions
222224
}

api/v1alpha3/machine_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,12 @@ type Machine struct {
252252
Status MachineStatus `json:"status,omitempty"`
253253
}
254254

255+
// GetConditions returns the set of conditions for this object.
255256
func (m *Machine) GetConditions() Conditions {
256257
return m.Status.Conditions
257258
}
258259

260+
// SetConditions sets the conditions on this object.
259261
func (m *Machine) SetConditions(conditions Conditions) {
260262
m.Status.Conditions = conditions
261263
}

api/v1alpha3/machinedeployment_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"k8s.io/apimachinery/pkg/util/intstr"
2222
)
2323

24+
// MachineDeploymentStrategyType defines the type of MachineDeployment rollout strategies.
2425
type MachineDeploymentStrategyType string
2526

2627
const (

api/v1alpha3/machinehealthcheck_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ type MachineHealthCheck struct {
132132
Status MachineHealthCheckStatus `json:"status,omitempty"`
133133
}
134134

135+
// GetConditions returns the set of conditions for this object.
135136
func (m *MachineHealthCheck) GetConditions() Conditions {
136137
return m.Status.Conditions
137138
}
138139

140+
// SetConditions sets the conditions on this object.
139141
func (m *MachineHealthCheck) SetConditions(conditions Conditions) {
140142
m.Status.Conditions = conditions
141143
}

api/v1alpha4/cluster_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,17 @@ type Cluster struct {
211211
Status ClusterStatus `json:"status,omitempty"`
212212
}
213213

214+
// GetConditions returns the set of conditions for this object.
214215
func (c *Cluster) GetConditions() Conditions {
215216
return c.Status.Conditions
216217
}
217218

219+
// SetConditions sets the conditions on this object.
218220
func (c *Cluster) SetConditions(conditions Conditions) {
219221
c.Status.Conditions = conditions
220222
}
221223

224+
// GetIPFamily returns a ClusterIPFamily from the configuration provided.
222225
func (c *Cluster) GetIPFamily() (ClusterIPFamily, error) {
223226
var podCIDRs, serviceCIDRs []string
224227
if c.Spec.ClusterNetwork != nil {
@@ -287,6 +290,7 @@ func ipFamilyForCIDRStrings(cidrs []string) (ClusterIPFamily, error) {
287290
}
288291
}
289292

293+
// ClusterIPFamily defines the types of supported IP families.
290294
type ClusterIPFamily int
291295

292296
// Define the ClusterIPFamily constants.

api/v1alpha4/cluster_webhook.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (c *Cluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
3636
var _ webhook.Defaulter = &Cluster{}
3737
var _ webhook.Validator = &Cluster{}
3838

39+
// Default satisfies the defaulting webhook interface.
3940
func (c *Cluster) Default() {
4041
if c.Spec.InfrastructureRef != nil && len(c.Spec.InfrastructureRef.Namespace) == 0 {
4142
c.Spec.InfrastructureRef.Namespace = c.Namespace

api/v1alpha4/machine_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ type Machine struct {
245245
Status MachineStatus `json:"status,omitempty"`
246246
}
247247

248+
// GetConditions returns the set of conditions for this object.
248249
func (m *Machine) GetConditions() Conditions {
249250
return m.Status.Conditions
250251
}
251252

253+
// SetConditions sets the conditions on this object.
252254
func (m *Machine) SetConditions(conditions Conditions) {
253255
m.Status.Conditions = conditions
254256
}

api/v1alpha4/machinedeployment_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"k8s.io/apimachinery/pkg/util/intstr"
2222
)
2323

24+
// MachineDeploymentStrategyType defines the type of MachineDeployment rollout strategies.
2425
type MachineDeploymentStrategyType string
2526

2627
const (

api/v1alpha4/machinehealthcheck_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ type MachineHealthCheck struct {
144144
Status MachineHealthCheckStatus `json:"status,omitempty"`
145145
}
146146

147+
// GetConditions returns the set of conditions for this object.
147148
func (m *MachineHealthCheck) GetConditions() Conditions {
148149
return m.Status.Conditions
149150
}
150151

152+
// SetConditions sets the conditions on this object.
151153
func (m *MachineHealthCheck) SetConditions(conditions Conditions) {
152154
m.Status.Conditions = conditions
153155
}

bootstrap/kubeadm/api/v1alpha3/kubeadmconfig_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ type KubeadmConfig struct {
143143
Status KubeadmConfigStatus `json:"status,omitempty"`
144144
}
145145

146+
// GetConditions returns the set of conditions for this object.
146147
func (c *KubeadmConfig) GetConditions() clusterv1.Conditions {
147148
return c.Status.Conditions
148149
}
149150

151+
// SetConditions sets the conditions on this object.
150152
func (c *KubeadmConfig) SetConditions(conditions clusterv1.Conditions) {
151153
c.Status.Conditions = conditions
152154
}

bootstrap/kubeadm/api/v1alpha4/kubeadmconfig_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ type KubeadmConfig struct {
136136
Status KubeadmConfigStatus `json:"status,omitempty"`
137137
}
138138

139+
// GetConditions returns the set of conditions for this object.
139140
func (c *KubeadmConfig) GetConditions() clusterv1.Conditions {
140141
return c.Status.Conditions
141142
}
142143

144+
// SetConditions sets the conditions on this object.
143145
func (c *KubeadmConfig) SetConditions(conditions clusterv1.Conditions) {
144146
c.Status.Conditions = conditions
145147
}

bootstrap/kubeadm/controllers/kubeadmconfig_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type KubeadmConfigReconciler struct {
7777
remoteClientGetter remote.ClusterClientGetter
7878
}
7979

80+
// Scope is a scoped struct used during reconciliation.
8081
type Scope struct {
8182
logr.Logger
8283
Config *bootstrapv1.KubeadmConfig

bootstrap/kubeadm/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var (
7777
healthAddr string
7878
)
7979

80+
// InitFlags initializes this manager's flags.
8081
func InitFlags(fs *pflag.FlagSet) {
8182
fs.StringVar(&metricsBindAddr, "metrics-bind-addr", ":8080",
8283
"The address the metric endpoint binds to.")

bootstrap/kubeadm/types/utils.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555
}
5656
)
5757

58+
// KubeVersionToKubeadmAPIGroupVersion maps a Kubernetes version to the correct Kubeadm API Group supported.
5859
func KubeVersionToKubeadmAPIGroupVersion(version semver.Version) (schema.GroupVersion, error) {
5960
switch {
6061
case version.LT(v1beta1KubeadmVersion):

cmd/clusterctl/api/v1alpha3/provider_type.go

+5
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,35 @@ type ProviderList struct {
151151
Items []Provider `json:"items"`
152152
}
153153

154+
// FilterByNamespace returns a new list of providers that reside in the namespace provided.
154155
func (l *ProviderList) FilterByNamespace(namespace string) []Provider {
155156
return l.filterBy(func(p Provider) bool {
156157
return p.Namespace == namespace
157158
})
158159
}
159160

161+
// FilterByProviderNameAndType returns a new list of provider that match the name and type.
160162
func (l *ProviderList) FilterByProviderNameAndType(provider string, providerType ProviderType) []Provider {
161163
return l.filterBy(func(p Provider) bool {
162164
return p.ProviderName == provider && p.Type == string(providerType)
163165
})
164166
}
165167

168+
// FilterByType returns a new list of providers that match the given type.
166169
func (l *ProviderList) FilterByType(providerType ProviderType) []Provider {
167170
return l.filterBy(func(p Provider) bool {
168171
return p.GetProviderType() == providerType
169172
})
170173
}
171174

175+
// FilterCore returns a new list of providers that are in the core.
172176
func (l *ProviderList) FilterCore() []Provider {
173177
return l.filterBy(func(p Provider) bool {
174178
return p.GetProviderType() == CoreProviderType
175179
})
176180
}
177181

182+
// FilterNonCore returns a new list of providers that are not in the core.
178183
func (l *ProviderList) FilterNonCore() []Provider {
179184
return l.filterBy(func(p Provider) bool {
180185
return p.GetProviderType() != CoreProviderType

cmd/clusterctl/client/alpha/rollout.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
2222
)
2323

24+
// MachineDeployment is a resource type.
2425
const MachineDeployment = "machinedeployment"
2526

2627
var validResourceTypes = []string{MachineDeployment}

cmd/clusterctl/client/client.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,22 @@ type clusterctlClient struct {
105105
alphaClient alpha.Client
106106
}
107107

108-
// RepositoryClientFactoryInput represents the inputs required by the
109-
// RepositoryClientFactory.
108+
// RepositoryClientFactoryInput represents the inputs required by the factory.
110109
type RepositoryClientFactoryInput struct {
111110
Provider Provider
112111
Processor Processor
113112
}
113+
114+
// RepositoryClientFactory is a factory of repository.Client from a given input.
114115
type RepositoryClientFactory func(RepositoryClientFactoryInput) (repository.Client, error)
115116

116-
// ClusterClientFactoryInput reporesents the inputs required by the
117-
// ClusterClientFactory.
117+
// ClusterClientFactoryInput reporesents the inputs required by the factory.
118118
type ClusterClientFactoryInput struct {
119119
Kubeconfig Kubeconfig
120120
Processor Processor
121121
}
122+
123+
// ClusterClientFactory is a factory of cluster.Client from a given input.
122124
type ClusterClientFactory func(ClusterClientFactoryInput) (cluster.Client, error)
123125

124126
// Ensure clusterctlClient implements Client.

cmd/clusterctl/client/cluster/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type clusterClient struct {
104104
processor yaml.Processor
105105
}
106106

107+
// RepositoryClientFactory defines a function that returns a new repository.Client.
107108
type RepositoryClientFactory func(provider config.Provider, configClient config.Client, options ...repository.Option) (repository.Client, error)
108109

109110
// ensure clusterClient implements Client.
@@ -218,6 +219,7 @@ func newClusterClient(kubeconfig Kubeconfig, configClient config.Client, options
218219
return client
219220
}
220221

222+
// Proxy defines a client proxy interface.
221223
type Proxy interface {
222224
// GetConfig returns the rest.Config
223225
GetConfig() (*rest.Config, error)

cmd/clusterctl/client/cluster/components.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/client"
3636
)
3737

38+
// DeleteOptions defines delete options.
3839
type DeleteOptions struct {
3940
Provider clusterctlv1.Provider
4041
IncludeNamespace bool

cmd/clusterctl/client/cluster/proxy.go

+3
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,17 @@ func listObjByGVK(c client.Client, groupVersion, kind string, options []client.L
217217
return objList, nil
218218
}
219219

220+
// ProxyOption defines a function that can change proxy options.
220221
type ProxyOption func(p *proxy)
221222

223+
// InjectProxyTimeout sets the proxy timeout.
222224
func InjectProxyTimeout(t time.Duration) ProxyOption {
223225
return func(p *proxy) {
224226
p.timeout = t
225227
}
226228
}
227229

230+
// InjectKubeconfigPaths sets the kubeconfig paths loading rules.
228231
func InjectKubeconfigPaths(paths []string) ProxyOption {
229232
return func(p *proxy) {
230233
p.configLoadingRules.Precedence = paths

cmd/clusterctl/client/cluster/template.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type templateClient struct {
5454
// ensure templateClient implements TemplateClient.
5555
var _ TemplateClient = &templateClient{}
5656

57+
// TemplateClientInput is an input struct for newTemplateClient.
5758
type TemplateClientInput struct {
5859
proxy Proxy
5960
configClient config.Client

cmd/clusterctl/client/config/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (p *provider) Less(other Provider) bool {
8383
(p.providerType.Order() == other.Type().Order() && p.name < other.Name())
8484
}
8585

86+
// NewProvider creates a new Provider with the given input.
8687
func NewProvider(name string, url string, ttype clusterctlv1.ProviderType) Provider {
8788
return &provider{
8889
name: name,

cmd/clusterctl/client/init.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
2828
)
2929

30+
// NoopProvider determines if a provider passed in should behave as a no-op.
3031
const NoopProvider = "-"
3132

3233
// InitOptions carries the options supported by Init.

cmd/clusterctl/client/repository/template.go

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (t *template) Yaml() ([]byte, error) {
7070
return utilyaml.FromUnstructured(t.objs)
7171
}
7272

73+
// TemplateInput is an input struct for NewTemplate.
7374
type TemplateInput struct {
7475
RawArtifact []byte
7576
ConfigVariablesClient config.VariablesClient

cmd/clusterctl/client/repository/template_client.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type templateClient struct {
3838
processor yaml.Processor
3939
}
4040

41+
// TemplateClientInput is an input strict for newTemplateClient.
4142
type TemplateClientInput struct {
4243
version string
4344
provider config.Provider

cmd/clusterctl/client/tree/options.go

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (o *addObjectOptions) ApplyOptions(opts []AddObjectOption) *addObjectOption
3838
// e.g. control plane for KCP.
3939
type ObjectMetaName string
4040

41+
// ApplyToAdd applies the given options.
4142
func (n ObjectMetaName) ApplyToAdd(options *addObjectOptions) {
4243
options.MetaName = string(n)
4344
}
@@ -46,6 +47,7 @@ func (n ObjectMetaName) ApplyToAdd(options *addObjectOptions) {
4647
// when adding the node's children.
4748
type GroupingObject bool
4849

50+
// ApplyToAdd applies the given options.
4951
func (n GroupingObject) ApplyToAdd(options *addObjectOptions) {
5052
options.GroupingObject = bool(n)
5153
}
@@ -54,6 +56,7 @@ func (n GroupingObject) ApplyToAdd(options *addObjectOptions) {
5456
// same Status, Severity and Reason of the parent's object ready condition (it is an echo).
5557
type NoEcho bool
5658

59+
// ApplyToAdd applies the given options.
5760
func (n NoEcho) ApplyToAdd(options *addObjectOptions) {
5861
options.NoEcho = bool(n)
5962
}

0 commit comments

Comments
 (0)