Skip to content

Commit a1e343c

Browse files
committed
Migrate from phases to conditions
1 parent 786f358 commit a1e343c

File tree

99 files changed

+1493
-690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1493
-690
lines changed

api/v1alpha1/common.go

-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ package v1alpha1
22

33
import v1 "k8s.io/api/core/v1"
44

5-
type Phase string
6-
7-
const (
8-
PhaseNone Phase = ""
9-
PhaseCreating Phase = "Creating"
10-
11-
PhaseInitialize Phase = "Initialization"
12-
PhaseReady Phase = "Ready"
13-
PhasePending Phase = "Pending"
14-
PhaseError Phase = "Error"
15-
)
16-
175
type ExternalAccess struct {
186
// If set to true, the Operator will create an Ingress or a Route resource.
197
//For the plain Ingress there is no TLS configuration provided Route object uses "edge" termination by default.

api/v1alpha1/ctlog_types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type CTlogSpec struct {
3535

3636
// CTlogStatus defines the observed state of CTlog component
3737
type CTlogStatus struct {
38-
Phase Phase `json:"phase"`
3938
// +listType=map
4039
// +listMapKey=type
4140
// +patchStrategy=merge
@@ -46,7 +45,7 @@ type CTlogStatus struct {
4645

4746
//+kubebuilder:object:root=true
4847
//+kubebuilder:subresource:status
49-
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The component phase"
48+
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="The component status"
5049

5150
// CTlog is the Schema for the ctlogs API
5251
type CTlog struct {

api/v1alpha1/fulcio_types.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ type OIDCIssuer struct {
7777

7878
// FulcioStatus defines the observed state of Fulcio
7979
type FulcioStatus struct {
80-
Url string `json:"url,omitempty"`
81-
Phase Phase `json:"phase,omitempty"`
80+
Url string `json:"url,omitempty"`
8281
// +listType=map
8382
// +listMapKey=type
8483
// +patchStrategy=merge
@@ -89,7 +88,7 @@ type FulcioStatus struct {
8988

9089
//+kubebuilder:object:root=true
9190
//+kubebuilder:subresource:status
92-
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The component phase"
91+
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="The component status"
9392
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`,description="The component url"
9493

9594
// Fulcio is the Schema for the fulcios API

api/v1alpha1/rekor_types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type BackFillRedis struct {
5555
// RekorStatus defines the observed state of Rekor
5656
type RekorStatus struct {
5757
Url string `json:"url,omitempty"`
58-
Phase Phase `json:"phase,omitempty"`
5958
RekorSearchUIUrl string `json:"rekorSearchUIUrl,omitempty"`
6059
// +listType=map
6160
// +listMapKey=type
@@ -67,7 +66,7 @@ type RekorStatus struct {
6766

6867
//+kubebuilder:object:root=true
6968
//+kubebuilder:subresource:status
70-
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The component phase"
69+
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="The component status"
7170
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`,description="The component url"
7271

7372
// Rekor is the Schema for the rekors API

api/v1alpha1/trillian_types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type TrillianDB struct {
3939

4040
// TrillianStatus defines the observed state of Trillian
4141
type TrillianStatus struct {
42-
Phase Phase `json:"phase"`
4342
// +listType=map
4443
// +listMapKey=type
4544
// +patchStrategy=merge
@@ -50,7 +49,7 @@ type TrillianStatus struct {
5049

5150
//+kubebuilder:object:root=true
5251
//+kubebuilder:subresource:status
53-
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The component phase"
52+
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="The component status"
5453

5554
// Trillian is the Schema for the trillians API
5655
type Trillian struct {

api/v1alpha1/tuf_types.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ type TufKey struct {
2626

2727
// TufStatus defines the observed state of Tuf
2828
type TufStatus struct {
29-
Url string `json:"url,omitempty"`
30-
Phase Phase `json:"phase"`
29+
Url string `json:"url,omitempty"`
3130
// +listType=map
3231
// +listMapKey=type
3332
// +patchStrategy=merge
@@ -38,7 +37,7 @@ type TufStatus struct {
3837

3938
//+kubebuilder:object:root=true
4039
//+kubebuilder:subresource:status
41-
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The component phase"
40+
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="The component status"
4241
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`,description="The component url"
4342

4443
// Tuf is the Schema for the tufs API

config/crd/bases/rhtas.redhat.com_ctlogs.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ spec:
1616
scope: Namespaced
1717
versions:
1818
- additionalPrinterColumns:
19-
- description: The component phase
20-
jsonPath: .status.phase
21-
name: Phase
19+
- description: The component status
20+
jsonPath: .status.conditions[?(@.type=="Ready")].reason
21+
name: Status
2222
type: string
2323
name: v1alpha1
2424
schema:
@@ -187,10 +187,6 @@ spec:
187187
x-kubernetes-list-map-keys:
188188
- type
189189
x-kubernetes-list-type: map
190-
phase:
191-
type: string
192-
required:
193-
- phase
194190
type: object
195191
type: object
196192
served: true

config/crd/bases/rhtas.redhat.com_fulcios.yaml

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ spec:
1616
scope: Namespaced
1717
versions:
1818
- additionalPrinterColumns:
19-
- description: The component phase
20-
jsonPath: .status.phase
21-
name: Phase
19+
- description: The component status
20+
jsonPath: .status.conditions[?(@.type=="Ready")].reason
21+
name: Status
2222
type: string
2323
- description: The component url
2424
jsonPath: .status.url
@@ -275,8 +275,6 @@ spec:
275275
x-kubernetes-list-map-keys:
276276
- type
277277
x-kubernetes-list-type: map
278-
phase:
279-
type: string
280278
url:
281279
type: string
282280
type: object

config/crd/bases/rhtas.redhat.com_rekors.yaml

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ spec:
1616
scope: Namespaced
1717
versions:
1818
- additionalPrinterColumns:
19-
- description: The component phase
20-
jsonPath: .status.phase
21-
name: Phase
19+
- description: The component status
20+
jsonPath: .status.conditions[?(@.type=="Ready")].reason
21+
name: Status
2222
type: string
2323
- description: The component url
2424
jsonPath: .status.url
@@ -202,8 +202,6 @@ spec:
202202
x-kubernetes-list-map-keys:
203203
- type
204204
x-kubernetes-list-type: map
205-
phase:
206-
type: string
207205
rekorSearchUIUrl:
208206
type: string
209207
url:

config/crd/bases/rhtas.redhat.com_trillians.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ spec:
1616
scope: Namespaced
1717
versions:
1818
- additionalPrinterColumns:
19-
- description: The component phase
20-
jsonPath: .status.phase
21-
name: Phase
19+
- description: The component status
20+
jsonPath: .status.conditions[?(@.type=="Ready")].reason
21+
name: Status
2222
type: string
2323
name: v1alpha1
2424
schema:
@@ -137,10 +137,6 @@ spec:
137137
x-kubernetes-list-map-keys:
138138
- type
139139
x-kubernetes-list-type: map
140-
phase:
141-
type: string
142-
required:
143-
- phase
144140
type: object
145141
type: object
146142
served: true

config/crd/bases/rhtas.redhat.com_tufs.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ spec:
1616
scope: Namespaced
1717
versions:
1818
- additionalPrinterColumns:
19-
- description: The component phase
20-
jsonPath: .status.phase
21-
name: Phase
19+
- description: The component status
20+
jsonPath: .status.conditions[?(@.type=="Ready")].reason
21+
name: Status
2222
type: string
2323
- description: The component url
2424
jsonPath: .status.url
@@ -163,12 +163,8 @@ spec:
163163
x-kubernetes-list-map-keys:
164164
- type
165165
x-kubernetes-list-type: map
166-
phase:
167-
type: string
168166
url:
169167
type: string
170-
required:
171-
- phase
172168
type: object
173169
type: object
174170
served: true

controllers/constants/constants.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ package constants
22

33
const (
44
AppName = "trusted-artifact-signer"
5+
6+
// conditions
7+
Ready = "Ready"
8+
Pending = "Pending"
9+
Creating = "Creating"
10+
Initialize = "Initialize"
11+
Failure = "Failure"
512
)

controllers/ctlog/actions/constants.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package actions
33
const (
44
DeploymentName = "ctlog"
55
ComponentName = "ctlog"
6+
RBACName = "ctlog"
67

7-
RBACName = "ctlog"
8+
CertCondition = "FulcioCert"
89
)

controllers/ctlog/actions/createTree.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import (
88
"github.com/securesign/operator/controllers/common"
99
"github.com/securesign/operator/controllers/common/action"
1010
utils "github.com/securesign/operator/controllers/common/utils/kubernetes"
11+
"github.com/securesign/operator/controllers/constants"
1112
trillian "github.com/securesign/operator/controllers/trillian/actions"
1213
v1 "k8s.io/api/core/v1"
14+
"k8s.io/apimachinery/pkg/api/meta"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1316
)
1417

1518
func NewCreateTrillianTreeAction() action.Action[rhtasv1alpha1.CTlog] {
@@ -25,20 +28,31 @@ func (i createTrillianTreeAction) Name() string {
2528
}
2629

2730
func (i createTrillianTreeAction) CanHandle(instance *rhtasv1alpha1.CTlog) bool {
28-
return instance.Status.Phase == rhtasv1alpha1.PhaseCreating && (instance.Spec.TreeID == nil || *instance.Spec.TreeID == int64(0))
31+
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
32+
return c.Reason == constants.Creating && (instance.Spec.TreeID == nil || *instance.Spec.TreeID == int64(0))
2933
}
3034

3135
func (i createTrillianTreeAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CTlog) *action.Result {
3236
var err error
3337

3438
trillUrl, err := utils.GetInternalUrl(ctx, i.Client, instance.Namespace, trillian.LogserverDeploymentName)
3539
if err != nil {
36-
instance.Status.Phase = rhtasv1alpha1.PhaseError
40+
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
41+
Type: constants.Ready,
42+
Status: metav1.ConditionFalse,
43+
Reason: constants.Failure,
44+
Message: err.Error(),
45+
})
3746
return i.FailedWithStatusUpdate(ctx, fmt.Errorf("could not find trillian instance: %w", err), instance)
3847
}
3948
tree, err := common.CreateTrillianTree(ctx, "ctlog-tree", trillUrl+":8091")
4049
if err != nil {
41-
instance.Status.Phase = rhtasv1alpha1.PhaseError
50+
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
51+
Type: constants.Ready,
52+
Status: metav1.ConditionFalse,
53+
Reason: constants.Failure,
54+
Message: err.Error(),
55+
})
4256
return i.FailedWithStatusUpdate(ctx, fmt.Errorf("could not create trillian tree: %w", err), instance)
4357
}
4458
i.Recorder.Event(instance, v1.EventTypeNormal, "TreeID", "New Trillian tree created")

controllers/ctlog/actions/deployment.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/securesign/operator/controllers/common/action"
99
"github.com/securesign/operator/controllers/constants"
1010
"github.com/securesign/operator/controllers/ctlog/utils"
11+
"k8s.io/apimachinery/pkg/api/meta"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1113
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1214
)
1315

@@ -23,8 +25,9 @@ func (i deployAction) Name() string {
2325
return "deploy"
2426
}
2527

26-
func (i deployAction) CanHandle(tuf *rhtasv1alpha1.CTlog) bool {
27-
return tuf.Status.Phase == rhtasv1alpha1.PhaseCreating || tuf.Status.Phase == rhtasv1alpha1.PhaseReady
28+
func (i deployAction) CanHandle(instance *rhtasv1alpha1.CTlog) bool {
29+
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
30+
return c.Reason == constants.Creating || c.Reason == constants.Ready
2831
}
2932

3033
func (i deployAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CTlog) *action.Result {
@@ -42,11 +45,19 @@ func (i deployAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CTlog)
4245
}
4346

4447
if updated, err = i.Ensure(ctx, dp); err != nil {
48+
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
49+
Type: constants.Ready,
50+
Status: metav1.ConditionFalse,
51+
Reason: constants.Failure,
52+
Message: err.Error(),
53+
})
4554
return i.FailedWithStatusUpdate(ctx, fmt.Errorf("could not create CTlog: %w", err), instance)
4655
}
4756

4857
if updated {
49-
return i.Return()
58+
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{Type: constants.Ready,
59+
Status: metav1.ConditionFalse, Reason: constants.Creating, Message: "Service created"})
60+
return i.StatusUpdate(ctx, instance)
5061
} else {
5162
return i.Continue()
5263
}

controllers/ctlog/actions/generate_keys.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func (g generateKeys) Name() string {
3030
}
3131

3232
func (g generateKeys) CanHandle(instance *v1alpha1.CTlog) bool {
33-
return instance.Status.Phase == v1alpha1.PhaseCreating && instance.Spec.PrivateKeyRef == nil
33+
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
34+
return c.Reason == constants.Creating && instance.Spec.PrivateKeyRef == nil
3435
}
3536

3637
func (g generateKeys) Handle(ctx context.Context, instance *v1alpha1.CTlog) *action.Result {
@@ -54,11 +55,10 @@ func (g generateKeys) Handle(ctx context.Context, instance *v1alpha1.CTlog) *act
5455
return g.Failed(fmt.Errorf("could not set controller reference for Secret: %w", err))
5556
}
5657
if _, err = g.Ensure(ctx, secret); err != nil {
57-
instance.Status.Phase = v1alpha1.PhaseError
5858
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
59-
Type: string(v1alpha1.PhaseReady),
59+
Type: constants.Ready,
6060
Status: metav1.ConditionFalse,
61-
Reason: "Failure",
61+
Reason: constants.Failure,
6262
Message: err.Error(),
6363
})
6464
return g.FailedWithStatusUpdate(ctx, fmt.Errorf("could not create Secret: %w", err), instance)

0 commit comments

Comments
 (0)