generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: GcpNfsVolume Status.State is empty for long time if IpRange is g…
…etting created
- Loading branch information
1 parent
263b9d2
commit 51479b9
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gcpnfsvolume | ||
|
||
import ( | ||
"context" | ||
cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" | ||
"github.com/kyma-project/cloud-manager/pkg/composed" | ||
) | ||
|
||
func setProcessing(ctx context.Context, st composed.State) (error, context.Context) { | ||
state := st.(*State) | ||
logger := composed.LoggerFromCtx(ctx) | ||
nfsVolume := state.ObjAsGcpNfsVolume() | ||
|
||
//If deleting, continue with next steps. | ||
deleting := composed.IsMarkedForDeletion(state.Obj()) | ||
if deleting { | ||
return nil, nil | ||
} | ||
|
||
logger.WithValues("GcpNfsVolume :", nfsVolume.Name).Info("Checking States") | ||
|
||
//If state is not empty, continue | ||
if nfsVolume.Status.State != "" { | ||
return nil, nil | ||
} | ||
|
||
//Set the state to processing | ||
nfsVolume.Status.State = cloudresourcesv1beta1.StateProcessing | ||
return composed.UpdateStatus(nfsVolume). | ||
SetExclusiveConditions(). | ||
SuccessError(composed.StopWithRequeue). | ||
Run(ctx, state) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package gcpnfsvolume | ||
|
||
import ( | ||
"context" | ||
"github.com/go-logr/logr" | ||
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" | ||
"github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" | ||
"github.com/kyma-project/cloud-manager/pkg/composed" | ||
"github.com/stretchr/testify/suite" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
"testing" | ||
) | ||
|
||
type setProcessingSuite struct { | ||
suite.Suite | ||
ctx context.Context | ||
} | ||
|
||
func (suite *setProcessingSuite) SetupTest() { | ||
suite.ctx = log.IntoContext(context.Background(), logr.Discard()) | ||
} | ||
|
||
func (suite *setProcessingSuite) TestSetProcessingWhenDeleting() { | ||
|
||
obj := deletedGcpNfsVolume.DeepCopy() | ||
factory, err := newTestStateFactory() | ||
suite.Nil(err) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
//Get state object with GcpNfsVolume | ||
state := factory.newStateWith(obj) | ||
suite.Nil(err) | ||
|
||
err, ctx = setProcessing(ctx, state) | ||
suite.Nil(err) | ||
suite.Nil(ctx) | ||
} | ||
|
||
func (suite *setProcessingSuite) TestSetProcessingWhenStateDone() { | ||
|
||
obj := gcpNfsVolume.DeepCopy() | ||
factory, err := newTestStateFactory() | ||
suite.Nil(err) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
//Get state object with GcpNfsVolume | ||
obj.Status.State = v1beta1.StateReady | ||
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{ | ||
Type: cloudcontrolv1beta1.ConditionTypeReady, | ||
Status: metav1.ConditionTrue, | ||
Reason: "test", | ||
Message: "test", | ||
}) | ||
state := factory.newStateWith(obj) | ||
suite.Nil(err) | ||
|
||
err, ctx = setProcessing(ctx, state) | ||
suite.Nil(err) | ||
suite.Nil(ctx) | ||
} | ||
|
||
func (suite *setProcessingSuite) TestSetProcessingWhenStateError() { | ||
|
||
obj := gcpNfsVolume.DeepCopy() | ||
factory, err := newTestStateFactory() | ||
suite.Nil(err) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
//Get state object with GcpNfsVolume | ||
obj.Status.State = v1beta1.StateError | ||
meta.SetStatusCondition(&obj.Status.Conditions, metav1.Condition{ | ||
Type: cloudcontrolv1beta1.ConditionTypeError, | ||
Status: metav1.ConditionTrue, | ||
Reason: "test", | ||
Message: "test", | ||
}) | ||
state := factory.newStateWith(obj) | ||
suite.Nil(err) | ||
|
||
err, ctx = setProcessing(ctx, state) | ||
suite.Nil(err) | ||
suite.Nil(ctx) | ||
} | ||
|
||
func (suite *setProcessingSuite) TestSetProcessingWhenStateEmpty() { | ||
|
||
obj := gcpNfsVolume.DeepCopy() | ||
factory, err := newTestStateFactory() | ||
suite.Nil(err) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
//Set the Status.State to empty. | ||
obj.Status.State = "" | ||
|
||
//Get state object with GcpNfsVolume | ||
state := factory.newStateWith(obj) | ||
suite.Nil(err) | ||
|
||
err, ctx = setProcessing(ctx, state) | ||
suite.Equal(composed.StopWithRequeue, err) | ||
fromK8s := &v1beta1.GcpNfsVolume{} | ||
err = factory.skrCluster.K8sClient().Get(ctx, | ||
types.NamespacedName{Name: obj.Name, | ||
Namespace: obj.Namespace}, | ||
fromK8s) | ||
suite.Nil(err) | ||
suite.Equal(v1beta1.GcpNfsVolumeProcessing, fromK8s.Status.State) | ||
suite.Nil(fromK8s.Status.Conditions) | ||
} | ||
|
||
func TestSetProcessing(t *testing.T) { | ||
suite.Run(t, new(setProcessingSuite)) | ||
} |