Skip to content

Commit d749d10

Browse files
authored
Merge pull request #423 from anfredette/spec-to-status
Move BpfApplicationState Spec to Status
2 parents dd9c974 + c008e6f commit d749d10

28 files changed

+1562
-1434
lines changed

apis/v1alpha1/bpf_application_state_types.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,27 @@ type BpfApplicationProgramState struct {
6464
URetProbe *UprobeProgramInfoState `json:"uretprobe,omitempty"`
6565
}
6666

67-
// BpfApplicationSpec defines the desired state of BpfApplication
68-
type BpfApplicationStateSpec struct {
69-
// node is the name of the node for this BpfApplicationStateSpec.
70-
Node string `json:"node"`
67+
// BpfApplicationStateStatus reflects the status of the BpfApplication on the given node
68+
type BpfApplicationStateStatus struct {
7169
// updateCount is the number of times the BpfApplicationState has been updated. Set to 1
7270
// when the object is created, then it is incremented prior to each update.
7371
// This allows us to verify that the API server has the updated object prior
7472
// to starting a new Reconcile operation.
7573
UpdateCount int64 `json:"updateCount"`
74+
// node is the name of the node for this BpfApplicationStateSpec.
75+
Node string `json:"node"`
7676
// appLoadStatus reflects the status of loading the bpf application on the
7777
// given node.
7878
AppLoadStatus AppLoadStatus `json:"appLoadStatus"`
7979
// programs is a list of bpf programs contained in the parent application.
80-
// It is a map from the bpf program name to BpfApplicationProgramState
81-
// elements.
8280
Programs []BpfApplicationProgramState `json:"programs,omitempty"`
81+
// Conditions contains the overall status of the BpfApplicationState object
82+
// on the given node.
83+
// +patchMergeKey=type
84+
// +patchStrategy=merge
85+
// +listType=map
86+
// +listMapKey=type
87+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
8388
}
8489

8590
// +genclient
@@ -88,15 +93,14 @@ type BpfApplicationStateSpec struct {
8893
// +kubebuilder:resource:scope=Namespaced
8994

9095
// BpfApplicationState contains the per-node state of a BpfApplication.
91-
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=".spec.node"
96+
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=".status.node"
9297
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason`
9398
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
9499
type BpfApplicationState struct {
95100
metav1.TypeMeta `json:",inline"`
96101
metav1.ObjectMeta `json:"metadata,omitempty"`
97102

98-
Spec BpfApplicationStateSpec `json:"spec,omitempty"`
99-
Status BpfAppStatus `json:"status,omitempty"`
103+
Status BpfApplicationStateStatus `json:"status,omitempty"`
100104
}
101105

102106
// +kubebuilder:object:root=true
@@ -123,8 +127,8 @@ func (an BpfApplicationState) GetLabels() map[string]string {
123127
return an.Labels
124128
}
125129

126-
func (an BpfApplicationState) GetStatus() *BpfAppStatus {
127-
return &an.Status
130+
func (an BpfApplicationState) GetConditions() []metav1.Condition {
131+
return an.Status.Conditions
128132
}
129133

130134
func (an BpfApplicationState) GetClientObject() client.Object {

apis/v1alpha1/cluster_bpf_application_state_types.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'TracePoint' ? has(self.tracepoint) : !has(self.tracepoint)",message="tracepoint configuration is required when type is tracepoint, and forbidden otherwise"
3737
type ClBpfApplicationProgramState struct {
3838
BpfProgramStateCommon `json:",inline"`
39+
3940
// type specifies the bpf program type
4041
// +unionDiscriminator
4142
// +required
@@ -93,22 +94,27 @@ type ClBpfApplicationProgramState struct {
9394
TracePoint *ClTracepointProgramInfoState `json:"tracepoint,omitempty"`
9495
}
9596

96-
// BpfApplicationSpec defines the desired state of BpfApplication
97-
type ClBpfApplicationStateSpec struct {
98-
// node is the name of the node for this BpfApplicationStateSpec.
99-
Node string `json:"node"`
97+
// ClBpfApplicationStateStatus reflects the status of the ClusterBpfApplicationState on the given node
98+
type ClBpfApplicationStateStatus struct {
10099
// updateCount is the number of times the BpfApplicationState has been updated. Set to 1
101100
// when the object is created, then it is incremented prior to each update.
102101
// This allows us to verify that the API server has the updated object prior
103102
// to starting a new Reconcile operation.
104103
UpdateCount int64 `json:"updateCount"`
104+
// node is the name of the node for this BpfApplicationStateSpec.
105+
Node string `json:"node"`
105106
// appLoadStatus reflects the status of loading the bpf application on the
106107
// given node.
107108
AppLoadStatus AppLoadStatus `json:"appLoadStatus"`
108109
// programs is a list of bpf programs contained in the parent application.
109-
// It is a map from the bpf program name to BpfApplicationProgramState
110-
// elements.
111110
Programs []ClBpfApplicationProgramState `json:"programs,omitempty"`
111+
// Conditions contains the overall status of the ClusterBpfApplicationState
112+
// object on the given node.
113+
// +patchMergeKey=type
114+
// +patchStrategy=merge
115+
// +listType=map
116+
// +listMapKey=type
117+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
112118
}
113119

114120
// +genclient
@@ -118,15 +124,14 @@ type ClBpfApplicationStateSpec struct {
118124
// +kubebuilder:resource:scope=Cluster
119125

120126
// ClusterBpfApplicationState contains the per-node state of a BpfApplication.
121-
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=".spec.node"
127+
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=".status.node"
122128
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason`
123129
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
124130
type ClusterBpfApplicationState struct {
125131
metav1.TypeMeta `json:",inline"`
126132
metav1.ObjectMeta `json:"metadata,omitempty"`
127133

128-
Spec ClBpfApplicationStateSpec `json:"spec,omitempty"`
129-
Status BpfAppStatus `json:"status,omitempty"`
134+
Status ClBpfApplicationStateStatus `json:"status,omitempty"`
130135
}
131136

132137
// +kubebuilder:object:root=true
@@ -153,8 +158,8 @@ func (an ClusterBpfApplicationState) GetLabels() map[string]string {
153158
return an.Labels
154159
}
155160

156-
func (an ClusterBpfApplicationState) GetStatus() *BpfAppStatus {
157-
return &an.Status
161+
func (an ClusterBpfApplicationState) GetConditions() []metav1.Condition {
162+
return an.Status.Conditions
158163
}
159164

160165
func (an ClusterBpfApplicationState) GetClientObject() client.Object {

apis/v1alpha1/shared_types.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,14 @@ const (
339339
// node while attempting to apply the configuration described in the CRD.
340340
BpfAppStateCondProgramListChangedError BpfApplicationStateConditionType = "ProgramListChangedError"
341341

342-
// BpfAppStateCondDeleteError indicates that the BPF Application was marked
343-
// for deletion, but deletion was unsuccessful on the given node.
344-
BpfAppStateCondDeleteError BpfApplicationStateConditionType = "DeleteError"
342+
// BpfAppStateCondUnloadError indicates that the BPF Application was marked
343+
// for deletion, but unloading one or more programs was unsuccessful on the
344+
// given node.
345+
BpfAppStateCondUnloadError BpfApplicationStateConditionType = "UnloadError"
346+
347+
// BpfAppStateCondUnloaded indicates that the BPF Application was marked
348+
// for deletion, and has been successfully unloaded.
349+
BpfAppStateCondUnloaded BpfApplicationStateConditionType = "Unloaded"
345350
)
346351

347352
// Condition is a helper method to promote any given
@@ -375,13 +380,21 @@ func (b BpfApplicationStateConditionType) Condition() metav1.Condition {
375380
Reason: "Error",
376381
Message: "An error has occurred",
377382
}
378-
case BpfAppStateCondDeleteError:
379-
condType := string(BpfAppStateCondDeleteError)
383+
case BpfAppStateCondUnloadError:
384+
condType := string(BpfAppStateCondUnloadError)
380385
cond = metav1.Condition{
381386
Type: condType,
382387
Status: metav1.ConditionTrue,
383-
Reason: "Delete Error",
384-
Message: "Deletion failed on one or more nodes",
388+
Reason: "Unload Error",
389+
Message: "Unload failed for one or more programs",
390+
}
391+
case BpfAppStateCondUnloaded:
392+
condType := string(BpfAppStateCondUnloaded)
393+
cond = metav1.Condition{
394+
Type: condType,
395+
Status: metav1.ConditionTrue,
396+
Reason: "Unloaded",
397+
Message: "The application has been successfully unloaded",
385398
}
386399
}
387400
return cond

apis/v1alpha1/zz_generated.deepcopy.go

+22-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)