Skip to content

Commit

Permalink
fix code gen and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kmala committed Mar 14, 2024
1 parent 833f573 commit 4a66724
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 15 deletions.
5 changes: 5 additions & 0 deletions api/api-rules/violation_exceptions.list
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,KubeCloudS
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,KubeCloudSharedConfiguration,NodeSyncPeriod
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,KubeCloudSharedConfiguration,RouteReconciliationPeriod
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,KubeCloudSharedConfiguration,UseServiceAccountCredentials
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,WebhookConfiguration,CaBundle
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,WebhookConfiguration,MutatingWebhookConfiguration
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,WebhookConfiguration,ValidatingWebhookConfiguration
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,WebhookConfiguration,WebhookAddress
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,WebhookConfiguration,WebhookPort
API rule violation: names_match,k8s.io/cloud-provider/config/v1alpha1,WebhookConfiguration,Webhooks
API rule violation: names_match,k8s.io/controller-manager/config/v1alpha1,GenericControllerManagerConfiguration,Address
API rule violation: names_match,k8s.io/controller-manager/config/v1alpha1,GenericControllerManagerConfiguration,ClientConnection
Expand Down
40 changes: 39 additions & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions staging/src/k8s.io/cloud-provider/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,20 @@ func createOrUpdateWebhookConfiguration(ctx context.Context, webhooks map[string
} else {
if !apierrors.IsAlreadyExists(err) {
klog.ErrorS(err, "Unable to create validating webhook configuration with API server", "webhookconfiguration", klog.KObj(webhooksConfig.ValidatingWebhookConfiguration))
return fmt.Errorf("unable to create validating webhook configuration with API server %v", err)
return fmt.Errorf("unable to create validating webhook configuration with API server %w", err)
}

currentConfiguration, err := kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Get(ctx, webhooksConfig.ValidatingWebhookConfiguration.Name, metav1.GetOptions{})
if err != nil {
klog.ErrorS(err, "Unable to create validating webhook configuration with API server, error getting existing webhook configuration", "webhookconfiguration", webhooksConfig.ValidatingWebhookConfiguration.Name)
return fmt.Errorf("unable to get validating webhook configuration from API server %v", err)
return fmt.Errorf("unable to get validating webhook configuration from API server %w", err)
}
currentConfiguration.Webhooks = webhooksConfig.ValidatingWebhookConfiguration.Webhooks

_, err = kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Update(ctx, currentConfiguration, metav1.UpdateOptions{})
if err != nil {
klog.ErrorS(err, "Unable to update validating webhook configuration with API server", "webhookconfiguration", klog.KObj(webhooksConfig.ValidatingWebhookConfiguration))
return fmt.Errorf("unable to update validating webhook configuration with API server %v", err)
return fmt.Errorf("unable to update validating webhook configuration with API server %w", err)
}
}
}
Expand All @@ -238,20 +238,20 @@ func createOrUpdateWebhookConfiguration(ctx context.Context, webhooks map[string
} else {
if !apierrors.IsAlreadyExists(err) {
klog.ErrorS(err, "Unable to create mutating webhook configuration with API server", "webhookconfiguration", klog.KObj(webhooksConfig.MutatingWebhookConfiguration))
return fmt.Errorf("unable to create mutating webhook configuration with API server %v", err)
return fmt.Errorf("unable to create mutating webhook configuration with API server %w", err)
}

currentConfiguration, err := kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Get(ctx, webhooksConfig.MutatingWebhookConfiguration.Name, metav1.GetOptions{})
if err != nil {
klog.ErrorS(err, "Unable to create mutating webhook configuration with API server, error fetching existing webhook configuration", "webhookconfiguration", webhooksConfig.MutatingWebhookConfiguration.Name)
return fmt.Errorf("unable to get mutating webhook configuration from API server %v", err)
return fmt.Errorf("unable to get mutating webhook configuration from API server %w", err)
}
currentConfiguration.Webhooks = webhooksConfig.MutatingWebhookConfiguration.Webhooks

_, err = kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Update(ctx, currentConfiguration, metav1.UpdateOptions{})
if err != nil {
klog.ErrorS(err, "Unable to update mutating webhook configuration with API server", "webhookconfiguration", klog.KObj(webhooksConfig.MutatingWebhookConfiguration))
return fmt.Errorf("unable to update mutating webhook configuration with API server %v", err)
return fmt.Errorf("unable to update mutating webhook configuration with API server %w", err)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions staging/src/k8s.io/cloud-provider/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
nodeconfigv1alpha1 "k8s.io/cloud-provider/controllers/node/config/v1alpha1"
serviceconfigv1alpha1 "k8s.io/cloud-provider/controllers/service/config/v1alpha1"
Expand Down Expand Up @@ -98,4 +99,15 @@ type WebhookConfiguration struct {
// '-foo' means "disable 'foo'"
// first item for a particular name wins
Webhooks []string
// WebhookPort is the port that the controller-manager's webhook service runs on.
WebhookPort int32
// WebhookAddress is the IP address to serve on.
WebhookAddress string
// CaBundle is the ca certs to be used by apiserver for validating the webhook server certs.
CaBundle string
// ValidatingWebhookConfiguration is the config used for creating validation webhook config object.
ValidatingWebhookConfiguration *admissionregistrationv1.ValidatingWebhookConfiguration

// MutatingWebhookConfiguration is the config used for creating mutating webhook config object.
MutatingWebhookConfiguration *admissionregistrationv1.MutatingWebhookConfiguration
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions staging/src/k8s.io/cloud-provider/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions staging/src/k8s.io/cloud-provider/options/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (o *WebhookOptions) Validate(validatingWebhooks, mutatingWebhooks, disabled
if o.ValidatingWebhookConfiguration.Name == "" {
allErrors = append(allErrors, errors.New("validating webhook configuration name can't be empty"))
}
webhookConfigs := sets.NewString()
webhookConfigs := sets.New[string]()
for _, webhookConfig := range o.ValidatingWebhookConfiguration.Webhooks {
webhookConfigs.Insert(webhookConfig.Name)
}
Expand All @@ -114,7 +114,7 @@ func (o *WebhookOptions) Validate(validatingWebhooks, mutatingWebhooks, disabled
if o.MutatingWebhookConfiguration.Name == "" {
allErrors = append(allErrors, errors.New("mutating webhook configuration name can't be empty"))
}
webhookConfigs := sets.NewString()
webhookConfigs := sets.New[string]()
for _, webhookConfig := range o.MutatingWebhookConfiguration.Webhooks {
webhookConfigs.Insert(webhookConfig.Name)
}
Expand All @@ -134,7 +134,7 @@ func (o *WebhookOptions) getEnabledWebhooks(webhooks, disabledByDefaultWebhooks
return enabledWebhooks
}

func (o *WebhookOptions) validateWebhookConfiguration(webhookConfigs sets.String, webhooks []string) []error {
func (o *WebhookOptions) validateWebhookConfiguration(webhookConfigs sets.Set[string], webhooks []string) []error {
allErrors := []error{}
for _, name := range webhooks {
if !webhookConfigs.Has(name) {
Expand Down Expand Up @@ -181,7 +181,7 @@ func (o *WebhookOptions) ApplyTo(cfg *config.WebhookConfiguration) error {
func LoadConfigurationFromFile(path string, config runtime.Object) error {
configDef, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("failed to read file path %q: %+v", path, err)
return fmt.Errorf("failed to read file path %q: %w", path, err)
}

decoder := serializer.NewCodecFactory(runtime.NewScheme()).UniversalDecoder(admissionregistrationv1.SchemeGroupVersion)
Expand Down Expand Up @@ -287,7 +287,7 @@ func (o *WebhookServingOptions) ApplyTo(webhookCfg *config.WebhookConfiguration,
if webhookCfg.WebhookAddress == "0.0.0.0" {
ip, err := netutil.ChooseHostInterface()
if err != nil {
return fmt.Errorf("failed to get host ip %v", err)
return fmt.Errorf("failed to get host ip %w", err)
}
webhookCfg.WebhookAddress = ip.String()
}
Expand Down Expand Up @@ -322,14 +322,14 @@ func (o *WebhookServingOptions) ApplyTo(webhookCfg *config.WebhookConfiguration,
webhookCfg.CaBundle = string(caCert)
} else {
if err := o.MaybeDefaultWithSelfSignedCerts(webhookCfg.WebhookAddress, nil, []net.IP{netutils.ParseIPSloppy("127.0.0.1")}); err != nil {
return fmt.Errorf("error creating self-signed certificates for webhook: %v", err)
return fmt.Errorf("error creating self-signed certificates for webhook: %w", err)
}
(*cfg).Cert = o.ServerCert.GeneratedCert

cert, _ := o.ServerCert.GeneratedCert.CurrentCertKeyContent()
certs, err := certutil.ParseCertsPEM(cert)
if err != nil {
return fmt.Errorf("error parsing the certs %v", err)
return fmt.Errorf("error parsing the certs %w", err)
}
if len(certs) < 2 {
return fmt.Errorf("generated cert doesn't have the root cert, has only %v certs", len(certs))
Expand All @@ -340,7 +340,7 @@ func (o *WebhookServingOptions) ApplyTo(webhookCfg *config.WebhookConfiguration,
Bytes: certs[1].Raw,
})
if err != nil {
return fmt.Errorf("error encoding ca cert %v", err)
return fmt.Errorf("error encoding ca cert %w", err)
}
webhookCfg.CaBundle = caPEM.String()
}
Expand Down

0 comments on commit 4a66724

Please sign in to comment.