Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/operator/v1alpha1/certmanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CertManagerSpec struct {
// - "--acme-http01-solver-nameservers="8.8.8.8:53,1.1.1.1:53"
// - "--dns01-recursive-nameservers=8.8.8.8:53,1.1.1.1:53"
// - "--dns01-recursive-nameservers-only"
// - "--certificate-request-minimum-backoff-duration=30m"
//
// For OverrideEnvs,
// This field appends values to .spec.template.spec.containers[...].env. The container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,14 @@ spec:
- sign
- update
- watch
- apiGroups:
- config.openshift.io
resources:
- apiservers
verbs:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
Expand Down
1 change: 1 addition & 0 deletions bundle/manifests/operator.openshift.io_certmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ spec:
- "--acme-http01-solver-nameservers="8.8.8.8:53,1.1.1.1:53"
- "--dns01-recursive-nameservers=8.8.8.8:53,1.1.1.1:53"
- "--dns01-recursive-nameservers-only"
- "--certificate-request-minimum-backoff-duration=30m"

For OverrideEnvs,
This field appends values to .spec.template.spec.containers[...].env. The container
Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/operator.openshift.io_certmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ spec:
- "--acme-http01-solver-nameservers="8.8.8.8:53,1.1.1.1:53"
- "--dns01-recursive-nameservers=8.8.8.8:53,1.1.1.1:53"
- "--dns01-recursive-nameservers-only"
- "--certificate-request-minimum-backoff-duration=30m"

For OverrideEnvs,
This field appends values to .spec.template.spec.containers[...].env. The container
Expand Down
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ rules:
- sign
- update
- watch
- apiGroups:
- config.openshift.io
resources:
- apiservers
verbs:
- get
- list
- watch
- apiGroups:
- config.openshift.io
resources:
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/certmanager/certmanager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type CertManagerReconciler struct {
//+kubebuilder:rbac:groups="admissionregistration.k8s.io",resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups="apps",resources=deployments;replicasets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups="config.openshift.io",resources=certmanagers;clusteroperators;clusteroperators/status;infrastructures,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups="config.openshift.io",resources=apiservers,verbs=get;list;watch

//+kubebuilder:rbac:groups="cert-manager.io",resources=certificaterequests;certificaterequests/finalizers;certificaterequests/status;certificates;certificates/finalizers;certificates/status;clusterissuers;clusterissuers/status;issuers;issuers/status,verbs=get;list;watch;create;update;patch;delete;deletecollection
//+kubebuilder:rbac:groups="certificates.k8s.io",resources=certificatesigningrequests;certificatesigningrequests/status,verbs=get;list;watch;create;update;patch;delete
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/certmanager/generic_deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/openshift/library-go/pkg/operator/status"
"github.com/openshift/library-go/pkg/operator/v1helpers"

deploymentpkg "github.com/openshift/cert-manager-operator/pkg/controller/deployment"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pkg was renamed to github.com/openshift/cert-manager-operator/pkg/controller/certmanager and requires an update here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That calls WithClusterTLSProfileFromAPIServer in pkg/controller/deployment/tls_profile_hook.go.
So certmanager imports deployment for that one hook.
I guess changing it to pkg/controller/certmanager would only make sense if we moved tls_profile_hook.go into certmanager and dropped the deployment package.
Let me know what do you think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have moved the files in "common" dir and updated the import statements using PR#416. Later the changes will be used for istio-csr as well in future.

"github.com/openshift/cert-manager-operator/pkg/operator/assets"
certmanoperatorinformers "github.com/openshift/cert-manager-operator/pkg/operator/informers/externalversions"
"github.com/openshift/cert-manager-operator/pkg/operator/utils"
Expand Down Expand Up @@ -67,6 +68,9 @@ func newGenericDeploymentController(
))

informers = append(informers, infraInformerFactory.Config().V1().Infrastructures().Informer())

hooks = append(hooks, deploymentpkg.WithClusterTLSProfileFromAPIServer(infraInformerFactory.Config().V1().APIServers()))
informers = append(informers, infraInformerFactory.Config().V1().APIServers().Informer())
}

return deploymentcontroller.NewDeploymentController(
Expand Down
53 changes: 53 additions & 0 deletions pkg/controller/deployment/tls_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package deployment

import (
"fmt"
"sort"
"strings"
)

const (
certmanagerControllerDeployment = "cert-manager"
certmanagerWebhookDeployment = "cert-manager-webhook"
certmanagerCAinjectorDeployment = "cert-manager-cainjector"

argKeyValSeparator = "="
)

// mergeContainerArgs merges the source args with override values
// using a map that tracks unique keys for each arg containing a
// key value pair of form `key[=value]`.
func mergeContainerArgs(sourceArgs []string, overrideArgs []string) (destArgs []string) {
destArgMap := map[string]string{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
destArgMap := map[string]string{}
destArgMap := make(map[string]string)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in PR#416

parseArgMap(destArgMap, sourceArgs)
parseArgMap(destArgMap, overrideArgs)

destArgs = make([]string, len(destArgMap))
i := 0
for key, val := range destArgMap {
if len(val) > 0 {
destArgs[i] = fmt.Sprintf("%s%s%s", key, argKeyValSeparator, val)
} else {
destArgs[i] = key
}
i++
}
sort.Strings(destArgs)
return destArgs
}

// parseArgMap adds new entries to the map using keys
// parsed from each arg (of the form `key=[value]`) from the
// list of args.
func parseArgMap(argMap map[string]string, args []string) {
for _, arg := range args {
splitted := strings.Split(arg, argKeyValSeparator)
if len(splitted) > 0 && arg != "" {
key := splitted[0]
// ensure that for given arg eg. "--gate=FeatureA=true"
// the value remains "FeatureA=true" instead of just "FeatureA"
value := strings.Join(splitted[1:], argKeyValSeparator)
argMap[key] = value
}
}
}
49 changes: 49 additions & 0 deletions pkg/controller/deployment/tls_profile_hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package deployment
Comment thread
coderabbitai[bot] marked this conversation as resolved.

import (
"fmt"

appsv1 "k8s.io/api/apps/v1"

operatorv1 "github.com/openshift/api/operator/v1"
configinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1"

"github.com/openshift/cert-manager-operator/pkg/tlsprofile"
)

// WithClusterTLSProfileFromAPIServer applies TLS settings from
// apiserver.config.openshift.io/cluster to cert-manager operands. It is only
// registered when the shared config.openshift.io informer factory is available
// (OpenShift clusters).
func WithClusterTLSProfileFromAPIServer(apiServerInformer configinformersv1.APIServerInformer) func(*operatorv1.OperatorSpec, *appsv1.Deployment) error {
return func(_ *operatorv1.OperatorSpec, deployment *appsv1.Deployment) error {
if len(deployment.Spec.Template.Spec.Containers) != 1 {
return nil
}

apiServer, err := apiServerInformer.Lister().Get("cluster")
if err != nil {
return fmt.Errorf("failed to get apiserver.config.openshift.io/cluster: %w", err)
}

effective, err := tlsprofile.EffectiveSpec(apiServer.Spec.TLSSecurityProfile)
if err != nil {
return err
}

var extra []string
switch deployment.Name {
case certmanagerWebhookDeployment:
extra = tlsprofile.CertManagerWebhookTLSArgs(effective)
case certmanagerControllerDeployment, certmanagerCAinjectorDeployment:
extra = tlsprofile.CertManagerOperandMetricsTLSArgs(effective)
default:
return nil
}

container := deployment.Spec.Template.Spec.Containers[0]
container.Args = mergeContainerArgs(container.Args, extra)
deployment.Spec.Template.Spec.Containers[0] = container
return nil
}
}
Loading