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.
Merge pull request #53 from ravi-shankar-sap/main
GCP NFS Instance Reconcilation
- Loading branch information
Showing
16 changed files
with
228 additions
and
44 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
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
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
75 changes: 75 additions & 0 deletions
75
components/kcp/pkg/provider/gcp/iprange/checkGcpOperation.go
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,75 @@ | ||
package iprange | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/kyma-project/cloud-manager/components/kcp/api/cloud-control/v1beta1" | ||
"github.com/kyma-project/cloud-manager/components/kcp/pkg/provider/gcp/client" | ||
"github.com/kyma-project/cloud-manager/components/lib/composed" | ||
) | ||
|
||
func checkGcpOperation(ctx context.Context, st composed.State) (error, context.Context) { | ||
state := st.(*State) | ||
logger := composed.LoggerFromCtx(ctx) | ||
|
||
ipRange := state.ObjAsIpRange() | ||
opName := ipRange.Status.OpIdentifier | ||
logger.WithValues("ipRange :", ipRange.Name).Info("Checking Operation") | ||
|
||
//If no OpIdentifier, then continue to next action. | ||
if opName == "" { | ||
return nil, nil | ||
} | ||
|
||
//Check SyncPsa Operation.. | ||
if ipRange.Status.State == client.SyncPsaConnection || | ||
ipRange.Status.State == client.DeletePsaConnection { | ||
op, err := state.serviceNetworkingClient.GetOperation(ctx, opName) | ||
if err != nil { | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, err) | ||
return composed.LogErrorAndReturn(err, "Error getting operation from GCP", composed.StopWithRequeue, nil) | ||
} | ||
|
||
//Operation not completed yet.. requeue again. | ||
if op != nil && !op.Done { | ||
return composed.StopWithRequeueDelay(client.GcpRetryWaitTime), nil | ||
} | ||
|
||
//If not able to find the operation or it is completed, reset OpIdentifier. | ||
if op == nil || op.Done { | ||
ipRange.Status.OpIdentifier = "" | ||
} | ||
|
||
//If the operation failed, update the error status on the object. | ||
if op != nil && op.Error != nil { | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, errors.New(op.Error.Message)) | ||
} | ||
} else if ipRange.Status.State == client.SyncAddress || | ||
ipRange.Status.State == client.DeleteAddress { | ||
project := state.Scope().Spec.Scope.Gcp.Project | ||
op, err := state.computeClient.GetGlobalOperation(ctx, project, opName) | ||
if err != nil { | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, err) | ||
return composed.LogErrorAndReturn(err, "Error getting operation from GCP", composed.StopWithRequeue, nil) | ||
} | ||
|
||
//Operation not completed yet.. requeue again. | ||
if op != nil && op.Status != "DONE" { | ||
return composed.StopWithRequeueDelay(client.GcpRetryWaitTime), nil | ||
} | ||
|
||
//If not able to find the operation or it is completed, reset OpIdentifier. | ||
if op == nil || op.Status == "DONE" { | ||
ipRange.Status.OpIdentifier = "" | ||
} | ||
|
||
//If the operation failed, update the error status on the object. | ||
if op != nil && op.Error != nil { | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, errors.New(op.StatusMessage)) | ||
} | ||
|
||
} | ||
|
||
return nil, nil | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
components/kcp/pkg/provider/gcp/nfsinstance/checkGcpOperation.go
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,48 @@ | ||
package nfsinstance | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/kyma-project/cloud-manager/components/kcp/api/cloud-control/v1beta1" | ||
"github.com/kyma-project/cloud-manager/components/kcp/pkg/provider/gcp/client" | ||
"github.com/kyma-project/cloud-manager/components/lib/composed" | ||
) | ||
|
||
func checkGcpOperation(ctx context.Context, st composed.State) (error, context.Context) { | ||
state := st.(*State) | ||
logger := composed.LoggerFromCtx(ctx) | ||
|
||
nfsInstance := state.ObjAsNfsInstance() | ||
opName := nfsInstance.Status.OpIdentifier | ||
logger.WithValues("NfsInstance :", nfsInstance.Name).Info("Checking GCP Operation Status") | ||
|
||
//If no OpIdentifier, then continue to next action. | ||
if opName == "" { | ||
return nil, nil | ||
} | ||
|
||
project := state.Scope().Spec.Scope.Gcp.Project | ||
op, err := state.filestoreClient.GetOperation(ctx, project, opName) | ||
if err != nil { | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, err) | ||
return composed.LogErrorAndReturn(err, "Error getting operation from GCP", composed.StopWithRequeue, nil) | ||
} | ||
|
||
//Operation not completed yet.. requeue again. | ||
if op != nil && !op.Done { | ||
return composed.StopWithRequeueDelay(client.GcpRetryWaitTime), nil | ||
} | ||
|
||
//If not able to find the operation or it is completed, reset OpIdentifier. | ||
if op == nil || op.Done { | ||
nfsInstance.Status.OpIdentifier = "" | ||
} | ||
|
||
//If the operation failed, update the error status on the object. | ||
if op != nil && op.Error != nil { | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, errors.New(op.Error.Message)) | ||
} | ||
|
||
return nil, nil | ||
} |
27 changes: 27 additions & 0 deletions
27
components/kcp/pkg/provider/gcp/nfsinstance/checkUpdateMask.go
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,27 @@ | ||
package nfsinstance | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kyma-project/cloud-manager/components/kcp/pkg/common/actions/focal" | ||
"github.com/kyma-project/cloud-manager/components/lib/composed" | ||
) | ||
|
||
func checkUpdateMask(ctx context.Context, st composed.State) (error, context.Context) { | ||
state := st.(*State) | ||
logger := composed.LoggerFromCtx(ctx) | ||
|
||
nfsInstance := state.ObjAsNfsInstance() | ||
logger.WithValues("NfsInstance :", nfsInstance.Name).Info("Checking for Update Mask") | ||
|
||
//If the operation is not modify, continue. | ||
if state.operation != focal.MODIFY { | ||
return nil, nil | ||
} | ||
|
||
//If capacity is increased, add it to updateMask | ||
if nfsInstance.Spec.Instance.Gcp.CapacityGb > int(state.fsInstance.FileShares[0].CapacityGb) { | ||
state.updateMask = append(state.updateMask, "FileShares") | ||
} | ||
return nil, nil | ||
} |
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
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
Oops, something went wrong.