Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use kubernetes lease election for Trillian log signer #851

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 12 additions & 2 deletions bundle/manifests/rhtas-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ metadata:
]
capabilities: Seamless Upgrades
containerImage: registry.redhat.io/rhtas/rhtas-rhel9-operator@sha256:52ba6cd82bc400a08c6f89811e8086126596a873b9b12619de8c5064a2d4faf7
createdAt: "2024-11-07T12:56:22Z"
createdAt: "2025-02-12T10:17:51Z"
features.operators.openshift.io/cnf: "false"
features.operators.openshift.io/cni: "false"
features.operators.openshift.io/csi: "false"
Expand All @@ -309,7 +309,7 @@ metadata:
features.operators.openshift.io/token-auth-azure: "false"
features.operators.openshift.io/token-auth-gcp: "false"
operators.openshift.io/valid-subscription: '["Red Hat Trusted Artifact Signer"]'
operators.operatorframework.io/builder: operator-sdk-v1.37.0
operators.operatorframework.io/builder: operator-sdk-v1.39.1
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4
repository: https://github.com/securesign/secure-sign-operator
support: Red Hat
Expand Down Expand Up @@ -458,6 +458,16 @@ spec:
- patch
- update
- watch
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- create
- get
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
10 changes: 10 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ rules:
- patch
- update
- watch
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- create
- get
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/constants/images.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package constants

var (
TrillianLogSignerImage = "registry.redhat.io/rhtas/trillian-logsigner-rhel9@sha256:2d707d12e4f65e1a92b4de11465a5976d55e15ad6c9fefe994646ccd44c83840"
TrillianLogSignerImage = "gcr.io/trillian-opensource-ci/log_signer:latest"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is temporary, it need to be changed before merge.

TrillianServerImage = "registry.redhat.io/rhtas/trillian-logserver-rhel9@sha256:7af78c7bc4df097ffeeef345f1d13289695f715221957579ee65daeef2fa3f5b"
TrillianDbImage = "registry.redhat.io/rhtas/trillian-database-rhel9@sha256:501612745e63e5504017079388bec191ffacf00ffdebde7be6ca5b8e4fd9d323"

Expand Down
3 changes: 2 additions & 1 deletion internal/controller/trillian/actions/logsigner/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (i deployAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Trilli
Namespace: instance.Namespace,
},
},
trillianUtils.EnsureServerDeployment(instance, constants.TrillianLogSignerImage, actions.LogsignerDeploymentName, actions.RBACName, labels, "--force_master=true"),
trillianUtils.EnsureServerDeployment(instance, constants.TrillianLogSignerImage, actions.LogsignerDeploymentName, actions.RBACName, labels,
"--election_system=k8s", "--lock_namespace=$(NAMESPACE)", "--lock_holder_identity=$(POD_NAME)"),
ensure.ControllerReference[*apps.Deployment](instance, i.Client),
ensure.Labels[*apps.Deployment](maps.Keys(labels), labels),
ensure.Proxy(),
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/trillian/actions/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func (i rbacAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Trillian
Resources: []string{"secrets"},
Verbs: []string{"create", "get", "update"},
},
rbacv1.PolicyRule{
APIGroups: []string{"coordination.k8s.io"},
Resources: []string{"leases"},
Verbs: []string{"create", "get", "update", "watch", "patch"},
},
),
); err != nil {
return i.Error(ctx, reconcile.TerminalError(fmt.Errorf("could not create Role: %w", err)), instance)
Expand Down
1 change: 1 addition & 0 deletions internal/controller/trillian/trillian_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type TrillianReconciler struct {
//+kubebuilder:rbac:groups=rhtas.redhat.com,resources=trillians,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=rhtas.redhat.com,resources=trillians/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=rhtas.redhat.com,resources=trillians/finalizers,verbs=update
//+kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;watch;create;update;patch

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
16 changes: 16 additions & 0 deletions internal/controller/trillian/utils/server-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ func EnsureServerDeployment(instance *v1alpha1.Trillian, image string, name stri
},
}

podNameEnv := kubernetes.FindEnvByNameOrCreate(container, "POD_NAME")
podNameEnv.ValueFrom = &core.EnvVarSource{
FieldRef: &core.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.name",
},
}

namespaceEnv := kubernetes.FindEnvByNameOrCreate(container, "NAMESPACE")
namespaceEnv.ValueFrom = &core.EnvVarSource{
FieldRef: &core.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.namespace",
},
}

port := kubernetes.FindPortByNameOrCreate(container, "8091-tcp")
port.ContainerPort = 8091
port.Protocol = core.ProtocolTCP
Expand Down
Loading