Skip to content

Commit

Permalink
chore(operator): restructure packages (#469)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored Nov 28, 2022
1 parent d521669 commit 41f21eb
Show file tree
Hide file tree
Showing 58 changed files with 800 additions and 607 deletions.
8 changes: 5 additions & 3 deletions operator/controllers/common/evaluationhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/go-logr/logr"
klcv1alpha1 "github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1"
apicommon "github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
controllererrors "github.com/keptn/lifecycle-toolkit/operator/controllers/errors"
"github.com/keptn/lifecycle-toolkit/operator/controllers/interfaces"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -34,7 +36,7 @@ type EvaluationCreateAttributes struct {
}

func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx context.Context, reconcileObject client.Object, evaluationCreateAttributes EvaluationCreateAttributes) ([]klcv1alpha1.EvaluationStatus, apicommon.StatusSummary, error) {
piWrapper, err := NewPhaseItemWrapperFromClientObject(reconcileObject)
piWrapper, err := interfaces.NewPhaseItemWrapperFromClientObject(reconcileObject)
if err != nil {
return nil, apicommon.StatusSummary{}, err
}
Expand Down Expand Up @@ -124,7 +126,7 @@ func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx co
}
spanEvaluationTrace.End()
if err := r.SpanHandler.UnbindSpan(evaluation, ""); err != nil {
r.Log.Error(err, ErrCouldNotUnbindSpan, evaluation.Name)
r.Log.Error(err, controllererrors.ErrCouldNotUnbindSpan, evaluation.Name)
}
evaluationStatus.SetEndTime()
}
Expand All @@ -143,7 +145,7 @@ func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, phaseCtx co
}

func (r EvaluationHandler) CreateKeptnEvaluation(ctx context.Context, namespace string, reconcileObject client.Object, evaluationCreateAttributes EvaluationCreateAttributes) (string, error) {
piWrapper, err := NewPhaseItemWrapperFromClientObject(reconcileObject)
piWrapper, err := interfaces.NewPhaseItemWrapperFromClientObject(reconcileObject)
if err != nil {
return "", err
}
Expand Down
57 changes: 29 additions & 28 deletions operator/controllers/common/evaluationhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"testing"

"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1"
"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
apicommon "github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
kltfake "github.com/keptn/lifecycle-toolkit/operator/controllers/common/fake"
controllererrors "github.com/keptn/lifecycle-toolkit/operator/controllers/errors"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/trace"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -24,7 +25,7 @@ func TestEvaluationHandler(t *testing.T) {
object client.Object
createAttr EvaluationCreateAttributes
wantStatus []v1alpha1.EvaluationStatus
wantSummary common.StatusSummary
wantSummary apicommon.StatusSummary
evalObj v1alpha1.KeptnEvaluation
wantErr error
getSpanCalls int
Expand All @@ -36,8 +37,8 @@ func TestEvaluationHandler(t *testing.T) {
evalObj: v1alpha1.KeptnEvaluation{},
createAttr: EvaluationCreateAttributes{},
wantStatus: nil,
wantSummary: common.StatusSummary{},
wantErr: ErrCannotWrapToPhaseItem,
wantSummary: apicommon.StatusSummary{},
wantErr: controllererrors.ErrCannotWrapToPhaseItem,
getSpanCalls: 0,
unbindSpanCalls: 0,
},
Expand All @@ -48,10 +49,10 @@ func TestEvaluationHandler(t *testing.T) {
createAttr: EvaluationCreateAttributes{
SpanName: "",
EvaluationDefinition: "",
CheckType: common.PreDeploymentEvaluationCheckType,
CheckType: apicommon.PreDeploymentEvaluationCheckType,
},
wantStatus: []v1alpha1.EvaluationStatus(nil),
wantSummary: common.StatusSummary{},
wantSummary: apicommon.StatusSummary{},
wantErr: nil,
getSpanCalls: 0,
unbindSpanCalls: 0,
Expand All @@ -69,16 +70,16 @@ func TestEvaluationHandler(t *testing.T) {
createAttr: EvaluationCreateAttributes{
SpanName: "",
EvaluationDefinition: "eval-def",
CheckType: common.PreDeploymentEvaluationCheckType,
CheckType: apicommon.PreDeploymentEvaluationCheckType,
},
wantStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StatePending,
Status: apicommon.StatePending,
EvaluationName: "pre-eval-eval-def-",
},
},
wantSummary: common.StatusSummary{Total: 1, Pending: 1},
wantSummary: apicommon.StatusSummary{Total: 1, Pending: 1},
wantErr: nil,
getSpanCalls: 1,
unbindSpanCalls: 0,
Expand All @@ -92,11 +93,11 @@ func TestEvaluationHandler(t *testing.T) {
},
},
Status: v1alpha1.KeptnAppVersionStatus{
PreDeploymentEvaluationStatus: common.StateSucceeded,
PreDeploymentEvaluationStatus: apicommon.StateSucceeded,
PreDeploymentEvaluationTaskStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StateSucceeded,
Status: apicommon.StateSucceeded,
EvaluationName: "pre-eval-eval-def-",
},
},
Expand All @@ -106,16 +107,16 @@ func TestEvaluationHandler(t *testing.T) {
createAttr: EvaluationCreateAttributes{
SpanName: "",
EvaluationDefinition: "eval-def",
CheckType: common.PreDeploymentEvaluationCheckType,
CheckType: apicommon.PreDeploymentEvaluationCheckType,
},
wantStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StateSucceeded,
Status: apicommon.StateSucceeded,
EvaluationName: "pre-eval-eval-def-",
},
},
wantSummary: common.StatusSummary{Total: 1, Succeeded: 1},
wantSummary: apicommon.StatusSummary{Total: 1, Succeeded: 1},
wantErr: nil,
getSpanCalls: 0,
unbindSpanCalls: 0,
Expand All @@ -132,11 +133,11 @@ func TestEvaluationHandler(t *testing.T) {
},
},
Status: v1alpha1.KeptnAppVersionStatus{
PreDeploymentEvaluationStatus: common.StateSucceeded,
PreDeploymentEvaluationStatus: apicommon.StateSucceeded,
PreDeploymentEvaluationTaskStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StateProgressing,
Status: apicommon.StateProgressing,
EvaluationName: "pre-eval-eval-def-",
},
},
Expand All @@ -148,22 +149,22 @@ func TestEvaluationHandler(t *testing.T) {
Name: "pre-eval-eval-def-",
},
Status: v1alpha1.KeptnEvaluationStatus{
OverallStatus: common.StateFailed,
OverallStatus: apicommon.StateFailed,
},
},
createAttr: EvaluationCreateAttributes{
SpanName: "",
EvaluationDefinition: "eval-def",
CheckType: common.PreDeploymentEvaluationCheckType,
CheckType: apicommon.PreDeploymentEvaluationCheckType,
},
wantStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StateFailed,
Status: apicommon.StateFailed,
EvaluationName: "pre-eval-eval-def-",
},
},
wantSummary: common.StatusSummary{Total: 1, Failed: 1},
wantSummary: apicommon.StatusSummary{Total: 1, Failed: 1},
wantErr: nil,
getSpanCalls: 1,
unbindSpanCalls: 1,
Expand All @@ -180,11 +181,11 @@ func TestEvaluationHandler(t *testing.T) {
},
},
Status: v1alpha1.KeptnAppVersionStatus{
PreDeploymentEvaluationStatus: common.StateSucceeded,
PreDeploymentEvaluationStatus: apicommon.StateSucceeded,
PreDeploymentEvaluationTaskStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StateProgressing,
Status: apicommon.StateProgressing,
EvaluationName: "pre-eval-eval-def-",
},
},
Expand All @@ -196,22 +197,22 @@ func TestEvaluationHandler(t *testing.T) {
Name: "pre-eval-eval-def-",
},
Status: v1alpha1.KeptnEvaluationStatus{
OverallStatus: common.StateSucceeded,
OverallStatus: apicommon.StateSucceeded,
},
},
createAttr: EvaluationCreateAttributes{
SpanName: "",
EvaluationDefinition: "eval-def",
CheckType: common.PreDeploymentEvaluationCheckType,
CheckType: apicommon.PreDeploymentEvaluationCheckType,
},
wantStatus: []v1alpha1.EvaluationStatus{
{
EvaluationDefinitionName: "eval-def",
Status: common.StateSucceeded,
Status: apicommon.StateSucceeded,
EvaluationName: "pre-eval-eval-def-",
},
},
wantSummary: common.StatusSummary{Total: 1, Succeeded: 1},
wantSummary: apicommon.StatusSummary{Total: 1, Succeeded: 1},
wantErr: nil,
getSpanCalls: 1,
unbindSpanCalls: 1,
Expand Down Expand Up @@ -269,7 +270,7 @@ func TestEvaluationHandler_createEvaluation(t *testing.T) {
object: &v1alpha1.KeptnEvaluation{},
createAttr: EvaluationCreateAttributes{},
wantName: "",
wantErr: ErrCannotWrapToPhaseItem,
wantErr: controllererrors.ErrCannotWrapToPhaseItem,
},
{
name: "created evaluation",
Expand All @@ -286,7 +287,7 @@ func TestEvaluationHandler_createEvaluation(t *testing.T) {
createAttr: EvaluationCreateAttributes{
SpanName: "",
EvaluationDefinition: "eval-def",
CheckType: common.PreDeploymentEvaluationCheckType,
CheckType: apicommon.PreDeploymentEvaluationCheckType,
},
wantName: "pre-eval-eval-def-",
wantErr: nil,
Expand Down
Loading

0 comments on commit 41f21eb

Please sign in to comment.