Skip to content

Commit f11ec90

Browse files
authored
Achieve Lint Zero (#9907)
Enables lint checks for missing comments on exported methods/fields. The code-base is actually really good about commenting exported methods and packages so this didn't take super long. We can always disable it if it becomes painful, but I think it can be quite useful to force ourselves to err on the side of commenting things. Kept the exclusion for package comments because these throw up more false positives than they're worth (and don't worry `golint ./...`). After this change `golint ./...` runs clean except source/sink receiver names and contexts in test args, where golint is just wrong.
1 parent e5987bd commit f11ec90

File tree

39 files changed

+157
-18
lines changed

39 files changed

+157
-18
lines changed

.golangci.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ linters:
2929
- errcheck
3030

3131
issues:
32+
include:
33+
# Disable excluding issues about comments from golint.
34+
- EXC0002
35+
3236
exclude-rules:
3337
- path: test # Excludes /test, *_test.go etc.
3438
linters:
@@ -51,3 +55,8 @@ issues:
5155
text: "receiver name"
5256
linters:
5357
- golint
58+
59+
# This check has quite a few false positives where there isn't much value in the package comment.
60+
- text: "ST1000: at least one file in a package should have a package comment"
61+
linters:
62+
- stylecheck

pkg/apis/config/features.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
cm "knative.dev/pkg/configmap"
2424
)
2525

26+
// Flag is a string value which can be either Enabled, Disabled, or Allowed.
2627
type Flag string
2728

2829
const (

pkg/apis/doc.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// +k8s:deepcopy-gen=package
18+
19+
// Package apis contains the knative serving and autoscaling apis.
1720
// Api versions allow the api contract for a resource to be changed while keeping
18-
// backward compatibility by support multiple concurrent versions
21+
// backward compatibility by supporting multiple concurrent versions
1922
// of the same resource
20-
21-
// +k8s:deepcopy-gen=package
2223
package apis

pkg/apis/serving/k8s_validation.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var (
8181
)
8282
)
8383

84+
// ValidateVolumes validates the Volumes of a PodSpec.
8485
func ValidateVolumes(vs []corev1.Volume, mountedVolumes sets.String) (sets.String, *apis.FieldError) {
8586
volumes := make(sets.String, len(vs))
8687
var errs *apis.FieldError
@@ -628,6 +629,7 @@ func validateProbe(p *corev1.Probe) *apis.FieldError {
628629
return errs
629630
}
630631

632+
// ValidateNamespacedObjectReference validates an ObjectReference which may not contain a namespace.
631633
func ValidateNamespacedObjectReference(p *corev1.ObjectReference) *apis.FieldError {
632634
if p == nil {
633635
return nil
@@ -699,7 +701,7 @@ func ValidatePodSecurityContext(ctx context.Context, sc *corev1.PodSecurityConte
699701
// being validated.
700702
type userContainer struct{}
701703

702-
// WithUserContainer notes on the context that further validation or defaulting
704+
// WithinUserContainer notes on the context that further validation or defaulting
703705
// is within the context of a user container in the revision.
704706
func WithinUserContainer(ctx context.Context) context.Context {
705707
return context.WithValue(ctx, userContainer{}, struct{}{})
@@ -715,7 +717,7 @@ func WithinSidecarContainer(ctx context.Context) context.Context {
715717
return context.WithValue(ctx, sidecarContainer{}, struct{}{})
716718
}
717719

718-
// Check if we are in the context of a sidecar container in the revision.
720+
// IsInSidecarContainer checks if we are in the context of a sidecar container in the revision.
719721
func IsInSidecarContainer(ctx context.Context) bool {
720722
return ctx.Value(sidecarContainer{}) != nil
721723
}

pkg/apis/serving/v1/configuration_lifecycle.go

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func (cs *ConfigurationSpec) GetTemplate() *RevisionTemplateSpec {
7070
return &cs.Template
7171
}
7272

73+
// SetLatestCreatedRevisionName sets the LatestCreatedRevisionName on the
74+
// revision and sets the ConfigurationConditionReady state to unknown if this
75+
// does not match the LatestReadyRevisionName.
7376
func (cs *ConfigurationStatus) SetLatestCreatedRevisionName(name string) {
7477
cs.LatestCreatedRevisionName = name
7578
if cs.LatestReadyRevisionName != name {
@@ -78,27 +81,36 @@ func (cs *ConfigurationStatus) SetLatestCreatedRevisionName(name string) {
7881
}
7982
}
8083

84+
// SetLatestReadyRevisionName sets the LatestReadyRevisionName on the revision.
85+
// If this matches the LatestCreatedRevisionName, the
86+
// ConfigurationConditionReady condition is set to true.
8187
func (cs *ConfigurationStatus) SetLatestReadyRevisionName(name string) {
8288
cs.LatestReadyRevisionName = name
8389
if cs.LatestReadyRevisionName == cs.LatestCreatedRevisionName {
8490
configCondSet.Manage(cs).MarkTrue(ConfigurationConditionReady)
8591
}
8692
}
8793

94+
// MarkLatestCreatedFailed marks the ConfigurationConditionReady condition to
95+
// indicate that the Revision failed.
8896
func (cs *ConfigurationStatus) MarkLatestCreatedFailed(name, message string) {
8997
configCondSet.Manage(cs).MarkFalse(
9098
ConfigurationConditionReady,
9199
"RevisionFailed",
92100
"Revision %q failed with message: %s.", name, message)
93101
}
94102

103+
// MarkRevisionCreationFailed marks the ConfigurationConditionReady condition
104+
// to indicate the Revision creation failed.
95105
func (cs *ConfigurationStatus) MarkRevisionCreationFailed(message string) {
96106
configCondSet.Manage(cs).MarkFalse(
97107
ConfigurationConditionReady,
98108
"RevisionFailed",
99109
"Revision creation failed with message: %s.", message)
100110
}
101111

112+
// MarkLatestReadyDeleted marks the ConfigurationConditionReady condition to
113+
// indicate that the Revision was deleted.
102114
func (cs *ConfigurationStatus) MarkLatestReadyDeleted() {
103115
configCondSet.Manage(cs).MarkFalse(
104116
ConfigurationConditionReady,

pkg/apis/serving/v1/configuration_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const (
7373
ConfigurationConditionReady = apis.ConditionReady
7474
)
7575

76+
// IsConfigurationCondition returns true if the given ConditionType is a ConfigurationCondition.
7677
func IsConfigurationCondition(t apis.ConditionType) bool {
7778
return t == ConfigurationConditionReady
7879
}

pkg/apis/serving/v1/doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1 contains the Serving v1 API types.
18-
1917
// +k8s:deepcopy-gen=package
2018
// +groupName=serving.knative.dev
19+
20+
// Package v1 contains the Serving v1 API types.
2121
package v1

pkg/apis/serving/v1/revision_helpers.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ const (
4848
// UserQueueMetricsPortName specifies the port name to use for metrics
4949
// emitted by queue-proxy for end user.
5050
UserQueueMetricsPortName = "http-usermetric"
51+
)
5152

53+
const (
54+
// AnnotationParseErrorTypeMissing is the value of the Type field for
55+
// AnnotationParseErrors which indicate an annotation was missing.
5256
AnnotationParseErrorTypeMissing = "Missing"
57+
58+
// AnnotationParseErrorTypeInvalid is the value of the Type field for
59+
// AnnotationParseErrors which indicate an annotation was invalid.
5360
AnnotationParseErrorTypeInvalid = "Invalid"
54-
LabelParserErrorTypeMissing = "Missing"
55-
LabelParserErrorTypeInvalid = "Invalid"
5661
)
5762

5863
const (
@@ -77,13 +82,18 @@ type (
7782
RoutingState string
7883

7984
// +k8s:deepcopy-gen=false
85+
86+
// AnnotationParseError is the error type representing failures to parse annotations.
8087
AnnotationParseError struct {
8188
Type string
8289
Value string
8390
Err error
8491
}
8592

8693
// +k8s:deepcopy-gen=false
94+
95+
// LastPinnedParseError is the error returned when the lastPinned annotation
96+
// could not be parsed.
8797
LastPinnedParseError AnnotationParseError
8898
)
8999

pkg/apis/serving/v1/route_lifecycle.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -77,68 +77,98 @@ func (rs *RouteStatus) MarkIngressNotConfigured() {
7777
"IngressNotConfigured", "Ingress has not yet been reconciled.")
7878
}
7979

80+
// MarkTrafficAssigned marks the RouteConditionAllTrafficAssigned condition true.
8081
func (rs *RouteStatus) MarkTrafficAssigned() {
8182
routeCondSet.Manage(rs).MarkTrue(RouteConditionAllTrafficAssigned)
8283
}
8384

85+
// MarkUnknownTrafficError marks the RouteConditionAllTrafficAssigned condition
86+
// to indicate an error has occurred.
8487
func (rs *RouteStatus) MarkUnknownTrafficError(msg string) {
8588
routeCondSet.Manage(rs).MarkUnknown(RouteConditionAllTrafficAssigned, "Unknown", msg)
8689
}
8790

91+
// MarkConfigurationNotReady marks the RouteConditionAllTrafficAssigned
92+
// condition to indiciate the Revision is not yet ready.
8893
func (rs *RouteStatus) MarkConfigurationNotReady(name string) {
8994
routeCondSet.Manage(rs).MarkUnknown(RouteConditionAllTrafficAssigned,
9095
"RevisionMissing",
9196
"Configuration %q is waiting for a Revision to become ready.", name)
9297
}
9398

99+
// MarkConfigurationFailed marks the RouteConditionAllTrafficAssigned condition
100+
// to indicate the Revision has failed.
94101
func (rs *RouteStatus) MarkConfigurationFailed(name string) {
95102
routeCondSet.Manage(rs).MarkFalse(RouteConditionAllTrafficAssigned,
96103
"RevisionMissing",
97104
"Configuration %q does not have any ready Revision.", name)
98105
}
99106

107+
// MarkRevisionNotReady marks the RouteConditionAllTrafficAssigned condition to
108+
// indiciate the Revision is not yet ready.
100109
func (rs *RouteStatus) MarkRevisionNotReady(name string) {
101110
routeCondSet.Manage(rs).MarkUnknown(RouteConditionAllTrafficAssigned,
102111
"RevisionMissing",
103112
"Revision %q is not yet ready.", name)
104113
}
105114

115+
// MarkRevisionFailed marks the RouteConditionAllTrafficAssigned condition to
116+
// indiciate the Revision has failed.
106117
func (rs *RouteStatus) MarkRevisionFailed(name string) {
107118
routeCondSet.Manage(rs).MarkFalse(RouteConditionAllTrafficAssigned,
108119
"RevisionMissing",
109120
"Revision %q failed to become ready.", name)
110121
}
111122

123+
// MarkMissingTrafficTarget marks the RouteConditionAllTrafficAssigned
124+
// condition to indicate a reference traffic target was not found.
112125
func (rs *RouteStatus) MarkMissingTrafficTarget(kind, name string) {
113126
routeCondSet.Manage(rs).MarkFalse(RouteConditionAllTrafficAssigned,
114127
kind+"Missing",
115128
"%s %q referenced in traffic not found.", kind, name)
116129
}
117130

131+
// MarkCertificateProvisionFailed marks the
132+
// RouteConditionCertificateProvisioned condition to indicate that the
133+
// Certificate provisioning failed.
118134
func (rs *RouteStatus) MarkCertificateProvisionFailed(name string) {
119135
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
120136
"CertificateProvisionFailed",
121137
"Certificate %s fails to be provisioned.", name)
122138
}
123139

140+
// MarkCertificateReady marks the RouteConditionCertificateProvisioned
141+
// condition to indicate that the Certificate is ready.
124142
func (rs *RouteStatus) MarkCertificateReady(name string) {
125143
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
126144
}
127145

146+
// MarkCertificateNotReady marks the RouteConditionCertificateProvisioned
147+
// condition to indicate that the Certificate is not ready.
128148
func (rs *RouteStatus) MarkCertificateNotReady(name string) {
129149
routeCondSet.Manage(rs).MarkUnknown(RouteConditionCertificateProvisioned,
130150
"CertificateNotReady",
131151
"Certificate %s is not ready.", name)
132152
}
133153

154+
// MarkCertificateNotOwned changes the RouteConditionCertificateProvisioned
155+
// status to be false with the reason being that there is an existing
156+
// certificate with the name we wanted to use.
134157
func (rs *RouteStatus) MarkCertificateNotOwned(name string) {
135158
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
136159
"CertificateNotOwned",
137160
"There is an existing certificate %s that we don't own.", name)
138161
}
139162

140163
const (
141-
AutoTLSNotEnabledMessage = "autoTLS is not enabled"
164+
// AutoTLSNotEnabledMessage is the message which is set on the
165+
// RouteConditionCertificateProvisioned condition when it is set to True
166+
// because AutoTLS was not enabled.
167+
AutoTLSNotEnabledMessage = "autoTLS is not enabled"
168+
169+
// TLSNotEnabledForClusterLocalMessage is the message which is set on the
170+
// RouteConditionCertificateProvisioned condition when it is set to True
171+
// because the domain is cluster-local.
142172
TLSNotEnabledForClusterLocalMessage = "TLS is not enabled for cluster-local"
143173
)
144174

pkg/apis/serving/v1alpha1/doc.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// +k8s:deepcopy-gen=package
18+
// +groupName=serving.knative.dev
19+
20+
// Package v1alpha1 contains the v1alpha1 versions of the serving apis.
1721
// Api versions allow the api contract for a resource to be changed while keeping
1822
// backward compatibility by support multiple concurrent versions
1923
// of the same resource
20-
21-
// +k8s:deepcopy-gen=package
22-
// +groupName=serving.knative.dev
2324
package v1alpha1

pkg/apis/serving/v1alpha1/register.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ func Resource(resource string) schema.GroupResource {
3838
}
3939

4040
var (
41+
// SchemeBuilder registers the addKnownTypes function.
4142
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
42-
AddToScheme = SchemeBuilder.AddToScheme
43+
// AddToScheme applies all the stored functions to the scheme.
44+
AddToScheme = SchemeBuilder.AddToScheme
4345
)
4446

4547
// Adds the list of known types to Scheme.

pkg/autoscaler/aggregation/bucketing.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type TimedFloat64Buckets struct {
5656
windowTotal float64
5757
}
5858

59-
// Implements stringer interface.
59+
// String implements the Stringer interface.
6060
func (t *TimedFloat64Buckets) String() string {
6161
return spew.Sdump(t.buckets)
6262
}

pkg/autoscaler/config/autoscalerconfig/doc.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ limitations under the License.
1616

1717
// +k8s:deepcopy-gen=package
1818

19+
// Package autoscalerconfig contains the config struct for the autoscaler.
1920
package autoscalerconfig

pkg/deployment/doc.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ limitations under the License.
1616

1717
// +k8s:deepcopy-gen=package
1818

19+
// Package deployment manages the deployment config.
1920
package deployment

pkg/gc/config.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ import (
3030
)
3131

3232
const (
33+
// ConfigName is the name of the config map for garbage collection.
3334
ConfigName = "config-gc"
34-
Disabled = -1
35+
36+
// Disabled is the value (-1) used by various config map values to indicate
37+
// the setting is disabled.
38+
Disabled = -1
3539

3640
disabled = "disabled"
3741
)
3842

43+
// Config defines the tunable parameters for Garbage Collection.
3944
type Config struct {
4045
// Delay duration after a revision create before considering it for GC
4146
StaleRevisionCreateDelay time.Duration
@@ -79,6 +84,7 @@ func defaultConfig() *Config {
7984
}
8085
}
8186

87+
// NewConfigFromConfigMapFunc creates a Config from the supplied ConfigMap func.
8288
func NewConfigFromConfigMapFunc(ctx context.Context) func(configMap *corev1.ConfigMap) (*Config, error) {
8389
logger := logging.FromContext(ctx)
8490
minRevisionTimeout := controller.GetResyncPeriod(ctx)

pkg/gc/doc.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ limitations under the License.
1515
*/
1616

1717
// +k8s:deepcopy-gen=package
18+
1819
// Package gc manages garbage collection of old resources.
1920
package gc

pkg/leaderelection/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ import (
2020
kle "knative.dev/pkg/leaderelection"
2121
)
2222

23+
// ValidateConfig re-exports the NewConfigFromConfigMap function from pkg/leaderelection
24+
// in order for config_test.go to validate the config map.
2325
var ValidateConfig = kle.NewConfigFromConfigMap

pkg/reconciler/autoscaling/hpa/hpa.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Reconciler struct {
4747
// Check that our Reconciler implements pareconciler.Interface
4848
var _ pareconciler.Interface = (*Reconciler)(nil)
4949

50+
// ReconcileKind implements Interface.ReconcileKind.
5051
func (c *Reconciler) ReconcileKind(ctx context.Context, pa *pav1alpha1.PodAutoscaler) pkgreconciler.Event {
5152
logger := logging.FromContext(ctx)
5253
logger.Debug("PA exists")

pkg/reconciler/autoscaling/kpa/kpa.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type Reconciler struct {
7272
// Check that our Reconciler implements pareconciler.Interface
7373
var _ pareconciler.Interface = (*Reconciler)(nil)
7474

75+
// ReconcileKind implements Interface.ReconcileKind.
7576
func (c *Reconciler) ReconcileKind(ctx context.Context, pa *pav1alpha1.PodAutoscaler) pkgreconciler.Event {
7677
logger := logging.FromContext(ctx)
7778

pkg/reconciler/configuration/configuration.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Reconciler struct {
5555
// Check that our Reconciler implements configreconciler.Interface
5656
var _ configreconciler.Interface = (*Reconciler)(nil)
5757

58+
// ReconcileKind implements Interface.ReconcileKind.
5859
func (c *Reconciler) ReconcileKind(ctx context.Context, config *v1.Configuration) pkgreconciler.Event {
5960
logger := logging.FromContext(ctx)
6061
recorder := controller.GetEventRecorder(ctx)

0 commit comments

Comments
 (0)