Skip to content

Commit

Permalink
Preserve internal types
Browse files Browse the repository at this point in the history
- Needed to add custom conversion functions to handle conversions from
  public facing types to internal ones.

Signed-off-by: Cody W. Eilar <ecody@vmware.com>
  • Loading branch information
AcidLeroy committed Jul 27, 2023
1 parent 6212b63 commit 282a6d5
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 69 deletions.
8 changes: 4 additions & 4 deletions cmd/controller/app/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func Run(opts *config.ControllerConfiguration, stopCh <-chan struct{}) error {
g.Go(func() error {
log.V(logf.InfoLevel).Info("starting controller")

return iface.Run(int(opts.NumberOfConcurrentWorkers), rootCtx.Done())
return iface.Run(opts.NumberOfConcurrentWorkers, rootCtx.Done())
})
}

Expand Down Expand Up @@ -275,8 +275,8 @@ func buildControllerContextFactory(ctx context.Context, opts *config.ControllerC

ctxFactory, err := controller.NewContextFactory(ctx, controller.ContextOptions{
Kubeconfig: opts.KubeConfig,
KubernetesAPIQPS: float32(opts.KubernetesAPIQPS),
KubernetesAPIBurst: int(opts.KubernetesAPIBurst),
KubernetesAPIQPS: opts.KubernetesAPIQPS,
KubernetesAPIBurst: opts.KubernetesAPIBurst,
APIServerHost: opts.APIServerHost,

Namespace: opts.Namespace,
Expand All @@ -302,7 +302,7 @@ func buildControllerContextFactory(ctx context.Context, opts *config.ControllerC
},

SchedulerOptions: controller.SchedulerOptions{
MaxConcurrentChallenges: int(opts.MaxConcurrentChallenges),
MaxConcurrentChallenges: opts.MaxConcurrentChallenges,
},

IssuerOptions: controller.IssuerOptions{
Expand Down
10 changes: 5 additions & 5 deletions cmd/controller/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func AddConfigFlags(fs *pflag.FlagSet, c *config.ControllerConfiguration) {
"will be attempted.")
fs.StringVar(&c.KubeConfig, "kubeconfig", c.KubeConfig, ""+
"Paths to a kubeconfig. Only required if out-of-cluster.")
fs.Float64Var(&c.KubernetesAPIQPS, "kube-api-qps", c.KubernetesAPIQPS, "indicates the maximum queries-per-second requests to the Kubernetes apiserver")
fs.Int32Var(&c.KubernetesAPIBurst, "kube-api-burst", c.KubernetesAPIBurst, "the maximum burst queries-per-second of requests sent to the Kubernetes apiserver")
fs.Float32Var(&c.KubernetesAPIQPS, "kube-api-qps", c.KubernetesAPIQPS, "indicates the maximum queries-per-second requests to the Kubernetes apiserver")
fs.IntVar(&c.KubernetesAPIBurst, "kube-api-burst", c.KubernetesAPIBurst, "the maximum burst queries-per-second of requests sent to the Kubernetes apiserver")
fs.StringVar(&c.ClusterResourceNamespace, "cluster-resource-namespace", c.ClusterResourceNamespace, ""+
"Namespace to store resources owned by cluster scoped resources such as ClusterIssuer in. "+
"This must be specified if ClusterIssuers are enabled.")
Expand Down Expand Up @@ -180,9 +180,9 @@ func AddConfigFlags(fs *pflag.FlagSet, c *config.ControllerConfiguration) {
fs.Var(cliflag.NewMapStringBool(&c.FeatureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))

fs.Int32Var(&c.NumberOfConcurrentWorkers, "concurrent-workers", c.NumberOfConcurrentWorkers, ""+
fs.IntVar(&c.NumberOfConcurrentWorkers, "concurrent-workers", c.NumberOfConcurrentWorkers, ""+
"The number of concurrent workers for each controller.")
fs.Int32Var(&c.MaxConcurrentChallenges, "max-concurrent-challenges", c.MaxConcurrentChallenges, ""+
fs.IntVar(&c.MaxConcurrentChallenges, "max-concurrent-challenges", c.MaxConcurrentChallenges, ""+
"The maximum number of challenges that can be scheduled as 'processing' at once.")
fs.DurationVar(&c.DNS01CheckRetryPeriod, "dns01-check-retry-period", c.DNS01CheckRetryPeriod, ""+
"The duration the controller should wait between a propagation check. Despite the name, this flag is used to configure the wait period for both DNS01 and HTTP01 challenge propagation checks. For DNS01 challenges the propagation check verifies that a TXT record with the challenge token has been created. For HTTP01 challenges the propagation check verifies that the challenge token is served at the challenge URL."+
Expand Down Expand Up @@ -212,7 +212,7 @@ func AddConfigFlags(fs *pflag.FlagSet, c *config.ControllerConfiguration) {
"Leader election healthz checks within this timeout period after the lease expires will still return healthy")
fs.MarkHidden("internal-healthz-leader-election-timeout")

logf.AddFlags(c.Logging, fs)
logf.AddFlags(&c.Logging, fs)
}

func EnabledControllers(o *config.ControllerConfiguration) sets.String {
Expand Down
3 changes: 2 additions & 1 deletion internal/apis/config/controller/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
s.HealthzLeaderElectionTimeout = defaultTime
s.EnablePprof = true
s.PprofAddress = "something:1234"
s.Logging = logs.NewOptions()
temp := logs.NewOptions()
s.Logging = *temp
s.CopiedAnnotationPrefixes = []string{"*", "-kubectl.kubernetes.io/", "-fluxcd.io/", "-argocd.argoproj.io/"}

},
Expand Down
10 changes: 5 additions & 5 deletions internal/apis/config/controller/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type ControllerConfiguration struct {
KubeConfig string

// Indicates the maximum queries-per-second requests to the Kubernetes apiserver
KubernetesAPIQPS float64
KubernetesAPIQPS float32

// The maximum burst queries-per-second of requests sent to the Kubernetes apiserver
KubernetesAPIBurst int32
KubernetesAPIBurst int

// Namespace to store resources owned by cluster scoped resources such as ClusterIssuer in.
ClusterResourceNamespace string
Expand Down Expand Up @@ -169,10 +169,10 @@ type ControllerConfiguration struct {
EnableCertificateOwnerRef bool

// The number of concurrent workers for each controller.
NumberOfConcurrentWorkers int32
NumberOfConcurrentWorkers int

// The maximum number of challenges that can be scheduled as 'processing' at once.
MaxConcurrentChallenges int32
MaxConcurrentChallenges int

// The host and port that the metrics endpoint should listen on.
MetricsListenAddress string
Expand All @@ -193,7 +193,7 @@ type ControllerConfiguration struct {
// Enable profiling for controller.
EnablePprof bool

Logging *logs.Options
Logging logs.Options

// The duration the controller should wait between a propagation check. Despite
// the name, this flag is used to configure the wait period for both DNS01 and
Expand Down
68 changes: 68 additions & 0 deletions internal/apis/config/controller/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,71 @@ limitations under the License.
*/

package v1alpha1

import (
controller "github.com/cert-manager/cert-manager/internal/apis/config/controller"
v1alpha1 "github.com/cert-manager/cert-manager/pkg/apis/config/controller/v1alpha1"
conversion "k8s.io/apimachinery/pkg/conversion"
"k8s.io/component-base/logs"
logsapi "k8s.io/component-base/logs/api/v1"
)

func Convert_v1alpha1_ControllerConfiguration_To_controller_ControllerConfiguration(in *v1alpha1.ControllerConfiguration, out *controller.ControllerConfiguration, s conversion.Scope) error {
if err := autoConvert_v1alpha1_ControllerConfiguration_To_controller_ControllerConfiguration(in, out, s); err != nil {
return err
}
return nil
}

func Convert_controller_ControllerConfiguration_To_v1alpha1_ControllerConfiguration(in *controller.ControllerConfiguration, out *v1alpha1.ControllerConfiguration, s conversion.Scope) error {
if err := autoConvert_controller_ControllerConfiguration_To_v1alpha1_ControllerConfiguration(in, out, s); err != nil {
return err
}
return nil
}

func Convert_Pointer_float32_To_float32(in **float32, out *float32, s conversion.Scope) error {
if *in == nil {
*out = 0
return nil
}
*out = float32(**in)
return nil
}

func Convert_float32_To_Pointer_float32(in *float32, out **float32, s conversion.Scope) error {
temp := float32(*in)
*out = &temp
return nil
}

func Convert_Pointer_int32_To_int(in **int32, out *int, s conversion.Scope) error {
if *in == nil {
*out = 0
return nil
}
*out = int(**in)
return nil
}

func Convert_int_To_Pointer_int32(in *int, out **int32, s conversion.Scope) error {
temp := int32(*in)
*out = &temp
return nil
}

func Convert_Pointer_v1_LoggingConfiguration_To_v1_LoggingConfiguration(in **logsapi.LoggingConfiguration, out *logsapi.LoggingConfiguration, s conversion.Scope) error {
if *in == nil {
temp := logs.NewOptions()
temp.DeepCopyInto(out)
return nil
}
(*in).DeepCopyInto(out)
return nil
}

func Convert_v1_LoggingConfiguration_To_Pointer_v1_LoggingConfiguration(in *logsapi.LoggingConfiguration, out **logsapi.LoggingConfiguration, s conversion.Scope) error {
temp := in.DeepCopy()
*out = temp
return nil
}
82 changes: 82 additions & 0 deletions internal/apis/config/controller/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2021 The cert-manager 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 v1alpha1

import (
"reflect"
"testing"

logsapi "k8s.io/component-base/logs/api/v1"

"k8s.io/component-base/logs"
)

func TestConvert_Pointer_v1_LoggingConfiguration_To_v1_LoggingConfiguration(t *testing.T) {

testInput := logs.NewOptions()
generalInput := &testInput
var nilTestInput *logsapi.LoggingConfiguration = nil
var nilInput **logsapi.LoggingConfiguration = &nilTestInput

testcases := map[string]struct {
in **logsapi.LoggingConfiguration
expected logsapi.LoggingConfiguration
}{
"general case ": {
in: generalInput,
expected: *logs.NewOptions(),
},
"nil case": {
in: nilInput,
expected: *logs.NewOptions(),
},
}
for testName, testcase := range testcases {

out := logsapi.LoggingConfiguration{}
Convert_Pointer_v1_LoggingConfiguration_To_v1_LoggingConfiguration(testcase.in, &out, nil)
if !reflect.DeepEqual(testcase.expected, out) {
t.Errorf("\"%s\": expected \n\t%#v, got \n\t%#v\n", testName, testcase.expected, out)
}
if *testcase.in != nil && *testcase.in == &out {
t.Errorf("\"%s\": expected input and output to have different pointers, but they are the same.\n", testName)
}
}
}

func Test_Convert_v1_LoggingConfiguration_To_Pointer_v1_LoggingConfiguration(t *testing.T) {
testcases := map[string]struct {
in *logsapi.LoggingConfiguration
expected *logsapi.LoggingConfiguration
}{
"general case ": {
in: logs.NewOptions(),
expected: logs.NewOptions(),
},
}

for testName, testcase := range testcases {
temp := &logsapi.LoggingConfiguration{}
out := &temp
Convert_v1_LoggingConfiguration_To_Pointer_v1_LoggingConfiguration(testcase.in, out, nil)
if !reflect.DeepEqual(testcase.expected, *out) {
t.Errorf("\"%s\": expected \n\t%#v, got \n\t%#v\n", testName, testcase.expected, out)
}

}

}
2 changes: 1 addition & 1 deletion internal/apis/config/controller/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (
var (
defaultAPIServerHost = ""
defaultKubeconfig = ""
defaultKubernetesAPIQPS float64 = 20
defaultKubernetesAPIQPS float32 = 20
defaultKubernetesAPIBurst int32 = 50

defaultClusterResourceNamespace = "kube-system"
Expand Down

0 comments on commit 282a6d5

Please sign in to comment.