generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #50 from ravi-shankar-sap/main
GCP Nfs Reconciliation
- Loading branch information
Showing
13 changed files
with
356 additions
and
6 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
components/kcp/api/cloud-control/v1beta1/nfsinstance_gcp_types.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,39 @@ | ||
package v1beta1 | ||
|
||
type NfsOptionsGcp struct { | ||
// +kubebuilder:validation:Required | ||
Location string `json:"location"` | ||
|
||
// +kubebuilder:default=BASIC_HDD | ||
Tier GcpFileTier `json:"tier"` | ||
|
||
// +kubebuilder:validation:Pattern="^[a-z][a-z0-9_]*[a-z0-9]$" | ||
// +kubebuilder:default=vol1 | ||
FileShareName string `json:"fileShareName"` | ||
|
||
// +kubebuilder:default=1024 | ||
CapacityGb int `json:"capacityGb"` | ||
|
||
// +kubebuilder:default=PRIVATE_SERVICE_ACCESS | ||
ConnectMode GcpConnectMode `json:"connectMode"` | ||
} | ||
|
||
// +kubebuilder:validation:Enum=BASIC_HDD;BASIC_SSD;HIGH_SCALE_SSD;ENTERPRISE;ZONAL;REGIONAL | ||
type GcpFileTier string | ||
|
||
const ( | ||
BASIC_HDD = GcpFileTier("BASIC_HDD") | ||
BASIC_SSD = GcpFileTier("BASIC_SSD") | ||
HIGH_SCALE_SSD = GcpFileTier("HIGH_SCALE_SSD") | ||
ENTERPRISE = GcpFileTier("ENTERPRISE") | ||
ZONAL = GcpFileTier("ZONAL") | ||
REGIONAL = GcpFileTier("REGIONAL") | ||
) | ||
|
||
// +kubebuilder:validation:Enum=DIRECT_PEERING;PRIVATE_SERVICE_ACCESS | ||
type GcpConnectMode string | ||
|
||
const ( | ||
DIRECT_PEERING = GcpConnectMode("DIRECT_PEERING") | ||
PRIVATE_SERVICE_ACCESS = GcpConnectMode("PRIVATE_SERVICE_ACCESS") | ||
) |
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
20 changes: 20 additions & 0 deletions
20
components/kcp/api/cloud-control/v1beta1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
components/kcp/pkg/provider/gcp/nfsinstance/checkNUpdateState.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,66 @@ | ||
package nfsinstance | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kyma-project/cloud-manager/components/kcp/api/cloud-control/v1beta1" | ||
"github.com/kyma-project/cloud-manager/components/kcp/pkg/common/actions/focal" | ||
"github.com/kyma-project/cloud-manager/components/kcp/pkg/provider/gcp/client" | ||
"github.com/kyma-project/cloud-manager/components/lib/composed" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
) | ||
|
||
func checkNUpdateState(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("Updating State Info") | ||
|
||
//Compute State Info | ||
//Check and see whether the desiredState == actualState | ||
deleting := !state.Obj().GetDeletionTimestamp().IsZero() | ||
|
||
state.operation = focal.NONE | ||
if deleting { | ||
if state.fsInstance == nil { | ||
state.curState = client.Deleted | ||
} else if state.fsInstance.State != string(client.DELETING) { | ||
//If the filestore exists and not DELETING, delete it. | ||
state.operation = focal.DELETE | ||
state.curState = client.SyncFilestore | ||
} | ||
} else { | ||
if state.fsInstance == nil { | ||
//If filestore doesn't exist, add it. | ||
state.operation = focal.ADD | ||
state.curState = client.SyncFilestore | ||
} else if !state.doesFilestoreMatch() { | ||
//If the filestore exists, but does not match, update it. | ||
state.operation = focal.MODIFY | ||
state.curState = client.SyncFilestore | ||
} else if state.fsInstance.State == string(client.READY) { | ||
state.curState = v1beta1.ReadyState | ||
} | ||
} | ||
|
||
//Update State Info | ||
state.ObjAsNfsInstance().Status.State = state.curState | ||
|
||
if state.curState == v1beta1.ReadyState { | ||
state.ObjAsNfsInstance().Status.Hosts = state.fsInstance.Networks[0].IpAddresses | ||
meta.RemoveStatusCondition(state.ObjAsNfsInstance().Conditions(), v1beta1.ConditionTypeError) | ||
state.AddReadyCondition(ctx, "Filestore Instance provisioned in GCP.") | ||
} | ||
|
||
err := state.UpdateObjStatus(ctx) | ||
if err != nil { | ||
return composed.LogErrorAndReturn(err, "Error updating NfsInstance success status", composed.StopWithRequeue, nil) | ||
} | ||
|
||
if state.curState == v1beta1.ReadyState { | ||
return composed.StopAndForget, nil | ||
} | ||
|
||
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
43 changes: 43 additions & 0 deletions
43
components/kcp/pkg/provider/gcp/nfsinstance/loadNfsInstance.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,43 @@ | ||
package nfsinstance | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/kyma-project/cloud-manager/components/kcp/api/cloud-control/v1beta1" | ||
"github.com/kyma-project/cloud-manager/components/lib/composed" | ||
"google.golang.org/api/googleapi" | ||
) | ||
|
||
func loadNfsInstance(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("Loading GCP Filestore Instance") | ||
|
||
//Get GCP details. | ||
gcpScope := state.Scope().Spec.Scope.Gcp | ||
project := gcpScope.Project | ||
location := state.getGcpLocation() | ||
name := nfsInstance.Spec.RemoteRef.Name | ||
|
||
inst, err := state.filestoreClient.GetFilestoreInstance(ctx, project, location, name) | ||
if err != nil { | ||
|
||
var e *googleapi.Error | ||
if ok := errors.As(err, &e); ok { | ||
if e.Code == 404 { | ||
state.fsInstance = nil | ||
return nil, nil | ||
} | ||
} | ||
state.AddErrorCondition(ctx, v1beta1.ReasonGcpError, err) | ||
return composed.LogErrorAndReturn(err, "Error getting Filestore Instance from GCP", composed.StopWithRequeue, nil) | ||
} | ||
|
||
//Store the fsInstance in state | ||
state.fsInstance = inst | ||
|
||
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
Oops, something went wrong.