Skip to content

Commit

Permalink
Fix the issue when vpcID and vSwitchID are set
Browse files Browse the repository at this point in the history
When vpcID and vSwitchID are set,
descriptionResponse.Body.FileSystems.FileSystem becomes 0,
so we need to set fileSystemID first, not from descriptionResponse

Signed-off-by: Zheng Xi Zhou <zzxwill@gmail.com>
  • Loading branch information
zzxwill committed Jun 24, 2021
1 parent 59184e2 commit 1d21bef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions pkg/clients/nas/nas.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
errCodeFileSystemNotExist = "InvalidFileSystem.NotFound"
)

// ClientInterface will help fakeOSSClient in unit tests
// ClientInterface create a client inferface
type ClientInterface interface {
DescribeFileSystems(fileSystemID, fileSystemType, vpcID *string) (*sdk.DescribeFileSystemsResponse, error)
CreateFileSystem(fs v1alpha1.NASFileSystemParameter) (*sdk.CreateFileSystemResponse, error)
Expand All @@ -45,7 +45,7 @@ type SDKClient struct {
Client *sdk.Client
}

// NewClient will create OSS client
// NewClient will create NAS client
func NewClient(ctx context.Context, endpoint string, accessKeyID string, accessKeySecret string, securityToken string) (*SDKClient, error) {
config := &openapi.Config{
AccessKeyId: &accessKeyID,
Expand All @@ -60,7 +60,7 @@ func NewClient(ctx context.Context, endpoint string, accessKeyID string, accessK
return &SDKClient{Client: client}, nil
}

// DescribeFileSystems describes OSS FileSystem
// DescribeFileSystems describes NAS FileSystem
func (c *SDKClient) DescribeFileSystems(fileSystemID, fileSystemType, vpcID *string) (*sdk.DescribeFileSystemsResponse, error) {
describeFileSystemsRequest := &sdk.DescribeFileSystemsRequest{}
if fileSystemID != nil {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (c *SDKClient) CreateFileSystem(fs v1alpha1.NASFileSystemParameter) (*sdk.C
return res, err
}

// DeleteFileSystem deletes OSS NASFileSystem
// DeleteFileSystem deletes NASFileSystem
func (c *SDKClient) DeleteFileSystem(fileSystemID string) error {
deleteFileSystemRequest := &sdk.DeleteFileSystemRequest{
FileSystemId: tea.String(fileSystemID),
Expand All @@ -103,20 +103,23 @@ func (c *SDKClient) DeleteFileSystem(fileSystemID string) error {
}

// GenerateObservation generates NASFileSystemObservation from fileSystem information
func GenerateObservation(r *sdk.DescribeFileSystemsResponse) v1alpha1.NASFileSystemObservation {
// When vpcID and vSwitchID are set, descriptionResponse.Body.FileSystems.FileSystem becomes 0, so we need to set fileSystemID
// first, not from descriptionResponse
func GenerateObservation(fileSystemID *string, descriptionResponse *sdk.DescribeFileSystemsResponse) v1alpha1.NASFileSystemObservation {
observation := v1alpha1.NASFileSystemObservation{
FileSystemID: *fileSystemID,
}
var domain string
if len(r.Body.FileSystems.FileSystem) == 0 {
return v1alpha1.NASFileSystemObservation{}
if len(descriptionResponse.Body.FileSystems.FileSystem) == 0 {
return observation
}
if len(r.Body.FileSystems.FileSystem[0].MountTargets.MountTarget) == 0 {
if len(descriptionResponse.Body.FileSystems.FileSystem[0].MountTargets.MountTarget) == 0 {
domain = ""
} else {
domain = *r.Body.FileSystems.FileSystem[0].MountTargets.MountTarget[0].MountTargetDomain
}
return v1alpha1.NASFileSystemObservation{
FileSystemID: *r.Body.FileSystems.FileSystem[0].FileSystemId,
MountTargetDomain: domain,
domain = *descriptionResponse.Body.FileSystems.FileSystem[0].MountTargets.MountTarget[0].MountTargetDomain
}
observation.MountTargetDomain = domain
return observation
}

// IsUpdateToDate checks whether cr is up to date
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/nas/nas_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (e *External) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{ResourceExists: false}, nil
}

cr.Status.AtProvider = nasclient.GenerateObservation(filesystem)
cr.Status.AtProvider = nasclient.GenerateObservation(&fsID, filesystem)
var upToDate = nasclient.IsUpdateToDate(cr, filesystem)
if upToDate {
cr.SetConditions(xpv1.Available())
Expand Down Expand Up @@ -184,7 +184,7 @@ func (e *External) Create(ctx context.Context, mg resource.Managed) (managed.Ext
if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errFailedToDescribeNASFileSystem)
}
cr.Status.AtProvider = nasclient.GenerateObservation(fsRes)
cr.Status.AtProvider = nasclient.GenerateObservation(res.Body.FileSystemId, fsRes)
return managed.ExternalCreation{ConnectionDetails: GetConnectionDetails(cr)}, nil
}

Expand Down

0 comments on commit 1d21bef

Please # to comment.