-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathinterface.go
60 lines (52 loc) · 2.03 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2020 The Operator-SDK Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package conditions
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Condition can Get and Set a conditionType in an Operator Condition custom resource
// associated with the operator.
type Condition interface {
// Get fetches the condition on the operator's
// OperatorCondition. It returns an error if there are problems getting
// the OperatorCondition object or if the specific condition type does not
// exist.
Get(ctx context.Context) (*metav1.Condition, error)
// Set sets the specific condition on the operator's
// OperatorCondition to the provided status. If the condition is not
// present, it is added to the CR.
// To set a new condition, the user can call this method and provide optional
// parameters if required. It returns an error if there are problems getting or
// updating the OperatorCondition object.
Set(ctx context.Context, status metav1.ConditionStatus, option ...Option) error
}
// Option is a function that applies a change to a condition.
// This can be used to set optional condition fields, like reasons
// and messages.
type Option func(*metav1.Condition)
// WithReason is an Option, which adds the reason
// to the condition.
func WithReason(reason string) Option {
return func(c *metav1.Condition) {
c.Reason = reason
}
}
// WithMessage is an Option, which adds the reason
// to the condition.
func WithMessage(message string) Option {
return func(c *metav1.Condition) {
c.Message = message
}
}