From 805a9e703698d0a8a86f405f861f9e3fd91b29c6 Mon Sep 17 00:00:00 2001 From: Elijah Oyekunle Date: Mon, 11 Feb 2019 23:16:05 +0100 Subject: [PATCH] Fixes Golint Errors: staging/src/k8s.io/kube-aggregator (#73369) * fixed golint errors in staging/src/k8s.io/kube-aggregator * update openapi * unexported autoRegisterController --- api/openapi-spec/swagger.json | 2 + hack/.golint_failures | 9 ---- .../k8s.io/apiserver/pkg/registry/rest/BUILD | 1 + .../pkg/registry/rest/create_update.go | 52 +++++++++++++++++++ .../pkg/apis/apiregistration/doc.go | 2 +- .../pkg/apis/apiregistration/helpers.go | 4 ++ .../pkg/apis/apiregistration/helpers_test.go | 18 +++---- .../pkg/apis/apiregistration/register.go | 5 +- .../pkg/apis/apiregistration/types.go | 5 +- .../pkg/apis/apiregistration/v1/register.go | 5 +- .../pkg/apis/apiregistration/v1/types.go | 4 +- .../apis/apiregistration/v1beta1/register.go | 5 +- .../pkg/apis/apiregistration/v1beta1/types.go | 4 +- .../apiregistration/validation/validation.go | 4 ++ .../pkg/apiserver/apiserver.go | 12 +++-- .../pkg/apiserver/apiservice_controller.go | 4 ++ .../pkg/apiserver/handler_proxy_test.go | 6 +-- .../pkg/apiserver/resolvers.go | 2 +- .../kube-aggregator/pkg/cmd/server/start.go | 4 ++ .../autoregister/autoregister_controller.go | 7 +++ .../status/available_controller.go | 4 ++ .../pkg/registry/apiservice/BUILD | 1 + .../pkg/registry/apiservice/etcd/etcd.go | 5 +- .../pkg/registry/apiservice/strategy.go | 21 +++++--- 24 files changed, 145 insertions(+), 41 deletions(-) create mode 100644 staging/src/k8s.io/apiserver/pkg/registry/rest/create_update.go diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 9e56f3958e..f89d950a62 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -17251,6 +17251,7 @@ ] }, "io.k8s.kube-aggregator.pkg.apis.apiregistration.v1.APIServiceCondition": { + "description": "APIServiceCondition describes the state of an APIService at a particular point", "properties": { "lastTransitionTime": { "$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Time", @@ -17416,6 +17417,7 @@ ] }, "io.k8s.kube-aggregator.pkg.apis.apiregistration.v1beta1.APIServiceCondition": { + "description": "APIServiceCondition describes the state of an APIService at a particular point", "properties": { "lastTransitionTime": { "$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.Time", diff --git a/hack/.golint_failures b/hack/.golint_failures index f9b01c886b..947288e74a 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -647,16 +647,7 @@ staging/src/k8s.io/code-generator/cmd/conversion-gen/generators staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf staging/src/k8s.io/code-generator/cmd/lister-gen/generators staging/src/k8s.io/component-base/config/v1alpha1 -staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration -staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1 -staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1 -staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/validation -staging/src/k8s.io/kube-aggregator/pkg/apiserver -staging/src/k8s.io/kube-aggregator/pkg/cmd/server staging/src/k8s.io/kube-aggregator/pkg/controllers/autoregister -staging/src/k8s.io/kube-aggregator/pkg/controllers/status -staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice -staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd staging/src/k8s.io/kube-proxy/config/v1alpha1 staging/src/k8s.io/kubelet/config/v1beta1 staging/src/k8s.io/metrics/pkg/apis/custom_metrics diff --git a/staging/src/k8s.io/apiserver/pkg/registry/rest/BUILD b/staging/src/k8s.io/apiserver/pkg/registry/rest/BUILD index 7ad6f3b6fa..3d801d7a8c 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/rest/BUILD +++ b/staging/src/k8s.io/apiserver/pkg/registry/rest/BUILD @@ -22,6 +22,7 @@ go_library( name = "go_default_library", srcs = [ "create.go", + "create_update.go", "delete.go", "doc.go", "export.go", diff --git a/staging/src/k8s.io/apiserver/pkg/registry/rest/create_update.go b/staging/src/k8s.io/apiserver/pkg/registry/rest/create_update.go new file mode 100644 index 0000000000..37d6c8f8ad --- /dev/null +++ b/staging/src/k8s.io/apiserver/pkg/registry/rest/create_update.go @@ -0,0 +1,52 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package rest + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" +) + +// RESTCreateUpdateStrategy is a union of RESTUpdateStrategy and RESTCreateStrategy, +// and it defines the minimum validation, accepted input, and name generation +// behavior to create and update an object that follows Kubernetes API conventions. +type RESTCreateUpdateStrategy interface { + RESTCreateStrategy + // AllowCreateOnUpdate returns true if the object can be created by a PUT. + AllowCreateOnUpdate() bool + // PrepareForUpdate is invoked on update before validation to normalize + // the object. For example: remove fields that are not to be persisted, + // sort order-insensitive list fields, etc. This should not remove fields + // whose presence would be considered a validation error. + PrepareForUpdate(ctx context.Context, obj, old runtime.Object) + // ValidateUpdate is invoked after default fields in the object have been + // filled in before the object is persisted. This method should not mutate + // the object. + ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList + // AllowUnconditionalUpdate returns true if the object can be updated + // unconditionally (irrespective of the latest resource version), when + // there is no resource version specified in the object. + AllowUnconditionalUpdate() bool +} + +// Ensure that RESTCreateUpdateStrategy extends RESTCreateStrategy +var _ RESTCreateStrategy = (RESTCreateUpdateStrategy)(nil) + +// Ensure that RESTCreateUpdateStrategy extends RESTUpdateStrategy +var _ RESTUpdateStrategy = (RESTCreateUpdateStrategy)(nil) diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/doc.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/doc.go index 3bd2bc737c..394bcbc8ef 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/doc.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/doc.go @@ -17,5 +17,5 @@ limitations under the License. // +k8s:deepcopy-gen=package // +groupName=apiregistration.k8s.io -// Package api is the internal version of the API. +// Package apiregistration is the internal version of the API. package apiregistration // import "k8s.io/kube-aggregator/pkg/apis/apiregistration" diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers.go index 488ce21330..0f1d6bc6e1 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers.go @@ -25,6 +25,10 @@ import ( "k8s.io/apimachinery/pkg/version" ) +// SortedByGroupAndVersion sorts APIServices into their different groups, and then sorts them based on their versions. +// For example, the first element of the first array contains the APIService with the highest version number, in the +// group with the highest priority; while the last element of the last array contains the APIService with the lowest +// version number, in the group with the lowest priority. func SortedByGroupAndVersion(servers []*APIService) [][]*APIService { serversByGroupPriorityMinimum := ByGroupPriorityMinimum(servers) sort.Sort(serversByGroupPriorityMinimum) diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers_test.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers_test.go index 59b0ed61de..8553b9db55 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers_test.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/helpers_test.go @@ -38,13 +38,13 @@ func TestGetAPIServiceConditionByType(t *testing.T) { }{ { name: "Should find a matching condition from apiService", - apiService: makeNewApiService("v1", 100, conditionA, conditionB), + apiService: makeNewAPIService("v1", 100, conditionA, conditionB), conditionType: a, expectedCondition: &conditionA, }, { name: "Should not find a matching condition", - apiService: makeNewApiService("v1", 100, conditionA), + apiService: makeNewAPIService("v1", 100, conditionA), conditionType: b, expectedCondition: nil, }, @@ -69,19 +69,19 @@ func TestIsAPIServiceConditionTrue(t *testing.T) { }{ { name: "Should return false when condition of type is not present", - apiService: makeNewApiService("v1", 100), + apiService: makeNewAPIService("v1", 100), conditionType: a, expected: false, }, { name: "Should return false when condition of type is present but status is not ConditionTrue", - apiService: makeNewApiService("v1", 100, conditionAFalse), + apiService: makeNewAPIService("v1", 100, conditionAFalse), conditionType: a, expected: false, }, { name: "Should return false when condition of type is present but status is not ConditionTrue", - apiService: makeNewApiService("v1", 100, conditionATrue), + apiService: makeNewAPIService("v1", 100, conditionATrue), conditionType: a, expected: true, }, @@ -109,7 +109,7 @@ func TestSetAPIServiceCondition(t *testing.T) { }{ { name: "Should set a new condition with type where previously there was no condition of that type", - apiService: makeNewApiService("v1", 100), + apiService: makeNewAPIService("v1", 100), conditionType: a, initialCondition: nil, setCondition: conditionA1, @@ -117,7 +117,7 @@ func TestSetAPIServiceCondition(t *testing.T) { }, { name: "Should override a condition of type, when a condition of that type existed previously", - apiService: makeNewApiService("v1", 100, conditionA1), + apiService: makeNewAPIService("v1", 100, conditionA1), conditionType: a, initialCondition: &conditionA1, setCondition: conditionA2, @@ -175,7 +175,7 @@ func TestSortedAPIServicesByVersion(t *testing.T) { for _, tc := range tests { apiServices := make([]*APIService, 0) for _, v := range tc.versions { - apiServices = append(apiServices, makeNewApiService(v, 100)) + apiServices = append(apiServices, makeNewAPIService(v, 100)) } sortedServices := SortedByGroupAndVersion(apiServices) actual := make([]string, 0) @@ -188,7 +188,7 @@ func TestSortedAPIServicesByVersion(t *testing.T) { } } -func makeNewApiService(version string, priority int32, conditions ...APIServiceCondition) *APIService { +func makeNewAPIService(version string, priority int32, conditions ...APIServiceCondition) *APIService { status := APIServiceStatus{Conditions: conditions} return &APIService{Spec: APIServiceSpec{Version: version, VersionPriority: priority}, Status: status} } diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/register.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/register.go index 2ab61e9b4f..7b88df42fa 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/register.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/register.go @@ -21,6 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) +// GroupName is the API group for apiregistration const GroupName = "apiregistration.k8s.io" // SchemeGroupVersion is group version used to register these objects @@ -37,8 +38,10 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder is the scheme builder with scheme init functions to run for this API package SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to the given scheme. diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/types.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/types.go index 459edfe763..a8e345f81b 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/types.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/types.go @@ -57,7 +57,7 @@ type APIServiceSpec struct { // +optional CABundle []byte - // GroupPriorityMininum is the priority this group should have at least. Higher priority means that the group is preferred by clients over lower priority ones. + // GroupPriorityMinimum is the priority this group should have at least. Higher priority means that the group is preferred by clients over lower priority ones. // Note that other versions of this group might specify even higher GroupPriorityMininum values such that the whole group gets a higher priority. // The primary sort is based on GroupPriorityMinimum, ordered highest number to lowest (20 before 10). // The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo) @@ -78,6 +78,7 @@ type APIServiceSpec struct { VersionPriority int32 } +// ConditionStatus indicates the status of a condition (true, false, or unknown). type ConditionStatus string // These are valid condition statuses. "ConditionTrue" means a resource is in the condition; @@ -90,7 +91,7 @@ const ( ConditionUnknown ConditionStatus = "Unknown" ) -// APIConditionConditionType is a valid value for APIServiceCondition.Type +// APIServiceConditionType is a valid value for APIServiceCondition.Type type APIServiceConditionType string const ( diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/register.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/register.go index 70d277fdf4..cab9dff664 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/register.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/register.go @@ -22,6 +22,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) +// GroupName is the API group for apiregistration const GroupName = "apiregistration.k8s.io" // SchemeGroupVersion is group version used to register these objects @@ -33,11 +34,13 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder is the scheme builder with scheme init functions to run for this API package // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. SchemeBuilder runtime.SchemeBuilder localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme + // AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme + AddToScheme = localSchemeBuilder.AddToScheme ) func init() { diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/types.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/types.go index 171ed303ac..0a87c9fae3 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/types.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/types.go @@ -81,6 +81,7 @@ type APIServiceSpec struct { // Priority int64 `json:"priority" protobuf:"varint,6,opt,name=priority"` } +// ConditionStatus indicates the status of a condition (true, false, or unknown). type ConditionStatus string // These are valid condition statuses. "ConditionTrue" means a resource is in the condition; @@ -93,7 +94,7 @@ const ( ConditionUnknown ConditionStatus = "Unknown" ) -// APIConditionConditionType is a valid value for APIServiceCondition.Type +// APIServiceConditionType is a valid value for APIServiceCondition.Type type APIServiceConditionType string const ( @@ -101,6 +102,7 @@ const ( Available APIServiceConditionType = "Available" ) +// APIServiceCondition describes the state of an APIService at a particular point type APIServiceCondition struct { // Type is the type of the condition. Type APIServiceConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=APIServiceConditionType"` diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/register.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/register.go index 38babafa9e..f6a9fabb07 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/register.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/register.go @@ -22,6 +22,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) +// GroupName is the API group for apiregistration const GroupName = "apiregistration.k8s.io" // SchemeGroupVersion is group version used to register these objects @@ -33,11 +34,13 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder is the scheme builder with scheme init functions to run for this API package // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. SchemeBuilder runtime.SchemeBuilder localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme + // AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme + AddToScheme = localSchemeBuilder.AddToScheme ) func init() { diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/types.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/types.go index a95c5642d9..02bddab23a 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/types.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1/types.go @@ -81,6 +81,7 @@ type APIServiceSpec struct { // Priority int64 `json:"priority" protobuf:"varint,6,opt,name=priority"` } +// ConditionStatus indicates the status of a condition (true, false, or unknown). type ConditionStatus string // These are valid condition statuses. "ConditionTrue" means a resource is in the condition; @@ -93,7 +94,7 @@ const ( ConditionUnknown ConditionStatus = "Unknown" ) -// APIConditionConditionType is a valid value for APIServiceCondition.Type +// APIServiceConditionType is a valid value for APIServiceCondition.Type type APIServiceConditionType string const ( @@ -101,6 +102,7 @@ const ( Available APIServiceConditionType = "Available" ) +// APIServiceCondition describes the state of an APIService at a particular point type APIServiceCondition struct { // Type is the type of the condition. Type APIServiceConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=APIServiceConditionType"` diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/validation/validation.go b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/validation/validation.go index 725cf71337..0ffa3fc918 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/validation/validation.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/validation/validation.go @@ -27,6 +27,7 @@ import ( "k8s.io/kube-aggregator/pkg/apis/apiregistration" ) +// ValidateAPIService validates that the APIService is correctly defined. func ValidateAPIService(apiService *apiregistration.APIService) field.ErrorList { requiredName := apiService.Spec.Version + "." + apiService.Spec.Group @@ -88,6 +89,7 @@ func ValidateAPIService(apiService *apiregistration.APIService) field.ErrorList return allErrs } +// ValidateAPIServiceUpdate validates an update of APIService. func ValidateAPIServiceUpdate(newAPIService *apiregistration.APIService, oldAPIService *apiregistration.APIService) field.ErrorList { allErrs := validation.ValidateObjectMetaUpdate(&newAPIService.ObjectMeta, &oldAPIService.ObjectMeta, field.NewPath("metadata")) allErrs = append(allErrs, ValidateAPIService(newAPIService)...) @@ -95,6 +97,7 @@ func ValidateAPIServiceUpdate(newAPIService *apiregistration.APIService, oldAPIS return allErrs } +// ValidateAPIServiceStatus validates that the APIService status is one of 'True', 'False' or 'Unknown'. func ValidateAPIServiceStatus(status *apiregistration.APIServiceStatus, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} @@ -110,6 +113,7 @@ func ValidateAPIServiceStatus(status *apiregistration.APIServiceStatus, fldPath return allErrs } +// ValidateAPIServiceStatusUpdate validates an update of the status field of APIService. func ValidateAPIServiceStatusUpdate(newAPIService *apiregistration.APIService, oldAPIService *apiregistration.APIService) field.ErrorList { allErrs := validation.ValidateObjectMetaUpdate(&newAPIService.ObjectMeta, &oldAPIService.ObjectMeta, field.NewPath("metadata")) allErrs = append(allErrs, ValidateAPIServiceStatus(&newAPIService.Status, field.NewPath("status"))...) diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiserver.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiserver.go index 0741e5486d..e1be1847c5 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiserver.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiserver.go @@ -56,6 +56,7 @@ func init() { // legacyAPIServiceName is the fixed name of the only non-groupified API version const legacyAPIServiceName = "v1." +// ExtraConfig represents APIServices-specific configuration type ExtraConfig struct { // ProxyClientCert/Key are the client cert used to identify this proxy. Backing APIServices use // this to confirm the proxy's identity @@ -70,6 +71,7 @@ type ExtraConfig struct { ServiceResolver ServiceResolver } +// Config represents the configuration needed to create an APIAggregator. type Config struct { GenericConfig *genericapiserver.RecommendedConfig ExtraConfig ExtraConfig @@ -80,6 +82,7 @@ type completedConfig struct { ExtraConfig *ExtraConfig } +// CompletedConfig same as Config, just to swap private object. type CompletedConfig struct { // Embed a private pointer that cannot be instantiated outside of this package. *completedConfig @@ -131,11 +134,11 @@ func (cfg *Config) Complete() CompletedConfig { return CompletedConfig{&c} } -// New returns a new instance of APIAggregator from the given config. +// NewWithDelegate returns a new instance of APIAggregator from the given config. func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.DelegationTarget) (*APIAggregator, error) { // Prevent generic API server to install OpenAPI handler. Aggregator server // has its own customized OpenAPI handler. - openApiConfig := c.GenericConfig.OpenAPIConfig + openAPIConfig := c.GenericConfig.OpenAPIConfig c.GenericConfig.OpenAPIConfig = nil genericServer, err := c.GenericConfig.New("kube-aggregator", delegationTarget) @@ -202,13 +205,13 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg return nil }) - if openApiConfig != nil { + if openAPIConfig != nil { specDownloader := openapicontroller.NewDownloader() openAPIAggregator, err := openapicontroller.BuildAndRegisterAggregator( &specDownloader, delegationTarget, s.GenericAPIServer.Handler.GoRestfulContainer.RegisteredWebServices(), - openApiConfig, + openAPIConfig, s.GenericAPIServer.Handler.NonGoRestfulMux) if err != nil { return nil, err @@ -305,6 +308,7 @@ func (s *APIAggregator) RemoveAPIService(apiServiceName string) { // We don't need this right away because the handler properly delegates when no versions are present } +// DefaultAPIResourceConfigSource returns default configuration for an APIResource. func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig { ret := serverstorage.NewResourceConfig() // NOTE: GroupVersions listed here will be enabled by default. Don't put alpha versions in the list. diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiservice_controller.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiservice_controller.go index f0b61a67c3..b74143fea3 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiservice_controller.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiservice_controller.go @@ -34,11 +34,13 @@ import ( "k8s.io/kube-aggregator/pkg/controllers" ) +// APIHandlerManager defines the behaviour that an API handler should have. type APIHandlerManager interface { AddAPIService(apiService *apiregistration.APIService) error RemoveAPIService(apiServiceName string) } +// APIServiceRegistrationController is responsible for registering and removing API services. type APIServiceRegistrationController struct { apiHandlerManager APIHandlerManager @@ -51,6 +53,7 @@ type APIServiceRegistrationController struct { queue workqueue.RateLimitingInterface } +// NewAPIServiceRegistrationController returns a new APIServiceRegistrationController. func NewAPIServiceRegistrationController(apiServiceInformer informers.APIServiceInformer, apiHandlerManager APIHandlerManager) *APIServiceRegistrationController { c := &APIServiceRegistrationController{ apiHandlerManager: apiHandlerManager, @@ -83,6 +86,7 @@ func (c *APIServiceRegistrationController) sync(key string) error { return c.apiHandlerManager.AddAPIService(apiService) } +// Run starts APIServiceRegistrationController which will process all registration requests until stopCh is closed. func (c *APIServiceRegistrationController) Run(stopCh <-chan struct{}) { defer utilruntime.HandleCrash() defer c.queue.ShutDown() diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go index b4ed4b77bd..aa54adfff3 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go @@ -399,12 +399,12 @@ func TestProxyUpgrade(t *testing.T) { })) backendServer := httptest.NewUnstartedServer(backendHandler) - if cert, err := tls.X509KeyPair(svcCrt, svcKey); err != nil { + cert, err := tls.X509KeyPair(svcCrt, svcKey) + if err != nil { t.Errorf("https (valid hostname): %v", err) return - } else { - backendServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} } + backendServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} backendServer.StartTLS() defer backendServer.Close() diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/resolvers.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/resolvers.go index 532bc7f615..587b8a208d 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/resolvers.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/resolvers.go @@ -46,7 +46,7 @@ func (r *aggregatorEndpointRouting) ResolveEndpoint(namespace, name string) (*ur return proxy.ResolveEndpoint(r.services, r.endpoints, namespace, name) } -// NewEndpointServiceResolver returns a ServiceResolver that directly calls the +// NewClusterIPServiceResolver returns a ServiceResolver that directly calls the // service's cluster IP. func NewClusterIPServiceResolver(services listersv1.ServiceLister) ServiceResolver { return &aggregatorClusterRouting{ diff --git a/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go b/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go index e40f37136d..a86186f4fa 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/cmd/server/start.go @@ -36,6 +36,7 @@ import ( const defaultEtcdPathPrefix = "/registry/kube-aggregator.kubernetes.io/" +// AggregatorOptions contains everything necessary to create and run an API Aggregator. type AggregatorOptions struct { RecommendedOptions *genericoptions.RecommendedOptions APIEnablement *genericoptions.APIEnablementOptions @@ -99,6 +100,7 @@ func NewDefaultOptions(out, err io.Writer) *AggregatorOptions { return o } +// Validate validates all the required options. func (o AggregatorOptions) Validate(args []string) error { errors := []error{} errors = append(errors, o.RecommendedOptions.Validate()...) @@ -106,10 +108,12 @@ func (o AggregatorOptions) Validate(args []string) error { return utilerrors.NewAggregate(errors) } +// Complete fills in missing Options. func (o *AggregatorOptions) Complete() error { return nil } +// RunAggregator runs the API Aggregator. func (o AggregatorOptions) RunAggregator(stopCh <-chan struct{}) error { // TODO have a "real" external address if err := o.RecommendedOptions.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, nil); err != nil { diff --git a/staging/src/k8s.io/kube-aggregator/pkg/controllers/autoregister/autoregister_controller.go b/staging/src/k8s.io/kube-aggregator/pkg/controllers/autoregister/autoregister_controller.go index 3815c7d463..52776e72f0 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/controllers/autoregister/autoregister_controller.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/controllers/autoregister/autoregister_controller.go @@ -39,6 +39,7 @@ import ( ) const ( + // AutoRegisterManagedLabel is a label attached to the APIService that identifies how the APIService wants to be synced. AutoRegisterManagedLabel = "kube-aggregator.kubernetes.io/automanaged" // manageOnStart is a value for the AutoRegisterManagedLabel that indicates the APIService wants to be synced one time when the controller starts. @@ -81,6 +82,7 @@ type autoRegisterController struct { queue workqueue.RateLimitingInterface } +// NewAutoRegisterController creates a new autoRegisterController. func NewAutoRegisterController(apiServiceInformer informers.APIServiceInformer, apiServiceClient apiregistrationclient.APIServicesGetter) *autoRegisterController { c := &autoRegisterController{ apiServiceLister: apiServiceInformer.Lister(), @@ -127,6 +129,7 @@ func NewAutoRegisterController(apiServiceInformer informers.APIServiceInformer, return c } +// Run starts the autoregister controller in a loop which syncs API services until stopCh is closed. func (c *autoRegisterController) Run(threadiness int, stopCh <-chan struct{}) { // don't let panics crash the process defer utilruntime.HandleCrash() @@ -267,6 +270,7 @@ func (c *autoRegisterController) checkAPIService(name string) (err error) { return err } +// GetAPIServiceToSync gets a single API service to sync. func (c *autoRegisterController) GetAPIServiceToSync(name string) *apiregistration.APIService { c.apiServicesToSyncLock.RLock() defer c.apiServicesToSyncLock.RUnlock() @@ -274,10 +278,12 @@ func (c *autoRegisterController) GetAPIServiceToSync(name string) *apiregistrati return c.apiServicesToSync[name] } +// AddAPIServiceToSyncOnStart registers an API service to sync only when the controller starts. func (c *autoRegisterController) AddAPIServiceToSyncOnStart(in *apiregistration.APIService) { c.addAPIServiceToSync(in, manageOnStart) } +// AddAPIServiceToSync registers an API service to sync continuously. func (c *autoRegisterController) AddAPIServiceToSync(in *apiregistration.APIService) { c.addAPIServiceToSync(in, manageContinuously) } @@ -296,6 +302,7 @@ func (c *autoRegisterController) addAPIServiceToSync(in *apiregistration.APIServ c.queue.Add(apiService.Name) } +// RemoveAPIServiceToSync deletes a registered APIService. func (c *autoRegisterController) RemoveAPIServiceToSync(name string) { c.apiServicesToSyncLock.Lock() defer c.apiServicesToSyncLock.Unlock() diff --git a/staging/src/k8s.io/kube-aggregator/pkg/controllers/status/available_controller.go b/staging/src/k8s.io/kube-aggregator/pkg/controllers/status/available_controller.go index 364e00ae9f..acbd5c089b 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/controllers/status/available_controller.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/controllers/status/available_controller.go @@ -46,10 +46,12 @@ import ( "k8s.io/kube-aggregator/pkg/controllers" ) +// ServiceResolver knows how to convert a service reference into an actual location. type ServiceResolver interface { ResolveEndpoint(namespace, name string) (*url.URL, error) } +// AvailableConditionController handles checking the availability of registered API services. type AvailableConditionController struct { apiServiceClient apiregistrationclient.APIServicesGetter @@ -72,6 +74,7 @@ type AvailableConditionController struct { queue workqueue.RateLimitingInterface } +// NewAvailableConditionController returns a new AvailableConditionController. func NewAvailableConditionController( apiServiceInformer informers.APIServiceInformer, serviceInformer v1informers.ServiceInformer, @@ -309,6 +312,7 @@ func updateAPIServiceStatus(client apiregistrationclient.APIServicesGetter, orig return newAPIService, nil } +// Run starts the AvailableConditionController loop which manages the availability condition of API services. func (c *AvailableConditionController) Run(threadiness int, stopCh <-chan struct{}) { defer utilruntime.HandleCrash() defer c.queue.ShutDown() diff --git a/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/BUILD b/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/BUILD index 34c772a362..8cd7fac7d8 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/BUILD +++ b/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/BUILD @@ -16,6 +16,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library", "//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library", "//staging/src/k8s.io/apiserver/pkg/storage:go_default_library", "//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library", "//staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration:go_default_library", diff --git a/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go b/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go index 57fee68103..54651155d5 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go @@ -32,7 +32,7 @@ import ( "k8s.io/kube-aggregator/pkg/registry/apiservice" ) -// rest implements a RESTStorage for API services against etcd +// REST implements a RESTStorage for API services against etcd type REST struct { *genericregistry.Store } @@ -59,6 +59,7 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) *REST var swaggerMetadataDescriptions = metav1.ObjectMeta{}.SwaggerDoc() +// ConvertToTable implements the TableConvertor interface for REST. func (c *REST) ConvertToTable(ctx context.Context, obj runtime.Object, tableOptions runtime.Object) (*metav1beta1.Table, error) { table := &metav1beta1.Table{ ColumnDefinitions: []metav1beta1.TableColumnDefinition{ @@ -121,12 +122,14 @@ func NewStatusREST(scheme *runtime.Scheme, rest *REST) *StatusREST { return &StatusREST{store: &statusStore} } +// StatusREST implements the REST endpoint for changing the status of an APIService. type StatusREST struct { store *genericregistry.Store } var _ = rest.Patcher(&StatusREST{}) +// New creates a new APIService object. func (r *StatusREST) New() runtime.Object { return &apiregistration.APIService{} } diff --git a/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/strategy.go b/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/strategy.go index 636e8e4470..d9bfe543e2 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/strategy.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/strategy.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apiserver/pkg/registry/generic" + "k8s.io/apiserver/pkg/registry/rest" "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/names" @@ -37,7 +38,11 @@ type apiServerStrategy struct { names.NameGenerator } -func NewStrategy(typer runtime.ObjectTyper) apiServerStrategy { +// apiServerStrategy must implement rest.RESTCreateUpdateStrategy +var _ rest.RESTCreateUpdateStrategy = apiServerStrategy{} + +// NewStrategy creates a new apiServerStrategy. +func NewStrategy(typer runtime.ObjectTyper) rest.RESTCreateUpdateStrategy { return apiServerStrategy{typer, names.SimpleNameGenerator} } @@ -85,7 +90,8 @@ type apiServerStatusStrategy struct { names.NameGenerator } -func NewStatusStrategy(typer runtime.ObjectTyper) apiServerStatusStrategy { +// NewStatusStrategy creates a new apiServerStatusStrategy. +func NewStatusStrategy(typer runtime.ObjectTyper) rest.RESTUpdateStrategy { return apiServerStatusStrategy{typer, names.SimpleNameGenerator} } @@ -111,19 +117,22 @@ func (apiServerStatusStrategy) AllowUnconditionalUpdate() bool { return false } +// Canonicalize normalizes the object after validation. func (apiServerStatusStrategy) Canonicalize(obj runtime.Object) { } +// ValidateUpdate validates an update of apiServerStatusStrategy. func (apiServerStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateAPIServiceStatusUpdate(obj.(*apiregistration.APIService), old.(*apiregistration.APIService)) } +// GetAttrs returns the labels and fields of an API server for filtering purposes. func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { apiserver, ok := obj.(*apiregistration.APIService) if !ok { - return nil, nil, fmt.Errorf("given object is not a APIService.") + return nil, nil, fmt.Errorf("given object is not a APIService") } - return labels.Set(apiserver.ObjectMeta.Labels), APIServiceToSelectableFields(apiserver), nil + return labels.Set(apiserver.ObjectMeta.Labels), ToSelectableFields(apiserver), nil } // MatchAPIService is the filter used by the generic etcd backend to watch events @@ -136,7 +145,7 @@ func MatchAPIService(label labels.Selector, field fields.Selector) storage.Selec } } -// APIServiceToSelectableFields returns a field set that represents the object. -func APIServiceToSelectableFields(obj *apiregistration.APIService) fields.Set { +// ToSelectableFields returns a field set that represents the object. +func ToSelectableFields(obj *apiregistration.APIService) fields.Set { return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true) }