Skip to content

Commit

Permalink
fix: Updated common.Status to inheritance (#708)
Browse files Browse the repository at this point in the history
* fix: Updated common.Status to inheritance

* fix metadata
  • Loading branch information
whynowy committed Jun 26, 2020
1 parent 9e504f9 commit 6aabc5a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 20 deletions.
5 changes: 4 additions & 1 deletion api/event-bus.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ <h3 id="argoproj.io/v1alpha1.EventBusStatus">EventBusStatus
<tbody>
<tr>
<td>
<code>status</code></br>
<code>Status</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.Status
</em>
</td>
<td>
<p>
(Members of <code>Status</code> are embedded into this type.)
</p>
</td>
</tr>
<tr>
Expand Down
8 changes: 7 additions & 1 deletion api/event-bus.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,19 @@ Description

<td>

<code>status</code></br> <em>
<code>Status</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.Status </em>

</td>

<td>

<p>

(Members of <code>Status</code> are embedded into this type.)

</p>

</td>

</tr>
Expand Down
12 changes: 9 additions & 3 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,18 @@
"description": "EventBusStatus holds the status of the eventbus resource",
"type": "object",
"properties": {
"conditions": {
"description": "Conditions are the latest available observations of a resource's current state.",
"type": "array",
"items": {
"$ref": "#/definitions/io.argoproj.common.Condition"
},
"x-kubernetes-patch-merge-key": "type",
"x-kubernetes-patch-strategy": "merge"
},
"config": {
"description": "Config holds the fininalized configuration of EventBus",
"$ref": "#/definitions/io.argoproj.eventbus.v1alpha1.BusConfig"
},
"status": {
"$ref": "#/definitions/io.argoproj.common.Status"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion controllers/eventbus/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {

// Watch EventBus and enqueue EventBus object key
if err := c.Watch(&source.Kind{Type: &v1alpha1.EventBus{}}, &handler.EnqueueRequestForObject{}); err != nil {
mainLog.Error(err, "unable to watch EventBuses")
mainLog.Error(err, "unable to watch EventBus")
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/eventbus/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestReconcileNative(t *testing.T) {
}
err := r.reconcile(ctx, testBus)
assert.NoError(t, err)
assert.True(t, testBus.Status.Status.IsReady())
assert.True(t, testBus.Status.IsReady())
assert.NotNil(t, testBus.Status.Config.NATS)
assert.NotEmpty(t, testBus.Status.Config.NATS.URL)
assert.NotEmpty(t, testBus.Status.Config.NATS.ClusterID)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/common/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type Status struct {
Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

// InitConditions initializes the contions to Unknown
func (s *Status) InitConditions(conditionTypes ...ConditionType) {
// InitializeConditions initializes the contions to Unknown
func (s *Status) InitializeConditions(conditionTypes ...ConditionType) {
for _, t := range conditionTypes {
c := Condition{
Type: t,
Expand Down
20 changes: 17 additions & 3 deletions pkg/apis/eventbus/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions pkg/apis/eventbus/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type EventBusSpec struct {

// EventBusStatus holds the status of the eventbus resource
type EventBusStatus struct {
Status common.Status `json:"status,omitempty" protobuf:"bytes,1,opt,name=status"`
common.Status `json:",inline" protobuf:"bytes,1,opt,name=status"`
// Config holds the fininalized configuration of EventBus
Config BusConfig `json:"config,omitempty" protobuf:"bytes,2,opt,name=config"`
}
Expand Down Expand Up @@ -69,6 +69,7 @@ type NativeStrategy struct {
Persistence *PersistenceStrategy `json:"persistence,omitempty" protobuf:"bytes,4,opt,name=persistence"`
}

// GetReplicas return the replicas of statefulset
func (in *NativeStrategy) GetReplicas() int {
return int(in.Replicas)
}
Expand Down Expand Up @@ -118,30 +119,30 @@ const (

// InitConditions sets conditions to Unknown state.
func (s *EventBusStatus) InitConditions() {
s.Status.InitConditions(EventBusConditionDeployed, EventBusConditionConfigured)
s.InitializeConditions(EventBusConditionDeployed, EventBusConditionConfigured)
}

// MarkDeployed set the bus has been deployed.
func (s *EventBusStatus) MarkDeployed(reason, message string) {
s.Status.MarkTrueWithReason(EventBusConditionDeployed, reason, message)
s.MarkTrueWithReason(EventBusConditionDeployed, reason, message)
}

// MarkDeploying set the bus is deploying
func (s *EventBusStatus) MarkDeploying(reason, message string) {
s.Status.MarkUnknown(EventBusConditionDeployed, reason, message)
s.MarkUnknown(EventBusConditionDeployed, reason, message)
}

// MarkDeployFailed set the bus deploy failed
func (s *EventBusStatus) MarkDeployFailed(reason, message string) {
s.Status.MarkFalse(EventBusConditionDeployed, reason, message)
s.MarkFalse(EventBusConditionDeployed, reason, message)
}

// MarkConfigured set the bus configuration has been done.
func (s *EventBusStatus) MarkConfigured() {
s.Status.MarkTrue(EventBusConditionConfigured)
s.MarkTrue(EventBusConditionConfigured)
}

// MarkNotConfigured set the bus status not configured.
func (s *EventBusStatus) MarkNotConfigured(reason, message string) {
s.Status.MarkFalse(EventBusConditionConfigured, reason, message)
s.MarkFalse(EventBusConditionConfigured, reason, message)
}
2 changes: 1 addition & 1 deletion pkg/apis/eventbus/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestEventBusStatusIsReady(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.s.Status.IsReady()
got := test.s.IsReady()
if diff := cmp.Diff(test.expect, got); diff != "" {
t.Errorf("%s: unexpected condition (-expect, +got) = %v", test.name, diff)
}
Expand Down

0 comments on commit 6aabc5a

Please sign in to comment.