generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41b1ec6
commit f15003e
Showing
9 changed files
with
450 additions
and
288 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
85 changes: 85 additions & 0 deletions
85
internal/pkg/service/objectstorage/cloud/azure/container.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,85 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" | ||
|
||
"github.com/giantswarm/object-storage-operator/api/v1alpha1" | ||
) | ||
|
||
func (s AzureObjectStorageAdapter) existsContainer(ctx context.Context, bucket *v1alpha1.Bucket, storageAccountName string) (bool, error) { | ||
// Check BlobContainer name exists in StorageAccount | ||
_, err := s.blobContainerClient.Get( | ||
ctx, | ||
s.cluster.GetResourceGroup(), | ||
storageAccountName, | ||
bucket.Spec.Name, | ||
nil, | ||
) | ||
|
||
if err != nil { | ||
var respErr *azcore.ResponseError | ||
if errors.As(err, &respErr) { | ||
// If NOT FOUND error, that means the BlobContainer doesn't exist, so we return false | ||
if respErr.StatusCode == http.StatusNotFound { | ||
return false, nil | ||
} | ||
} | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
func (s AzureObjectStorageAdapter) upsertContainer(ctx context.Context, bucket *v1alpha1.Bucket, storageAccountName string) error { | ||
existsContainer, err := s.existsContainer(ctx, bucket, storageAccountName) | ||
if err != nil { | ||
return err | ||
} | ||
if !existsContainer { | ||
// Create Storage Container | ||
_, err := s.blobContainerClient.Create( | ||
ctx, | ||
s.cluster.GetResourceGroup(), | ||
storageAccountName, | ||
bucket.Spec.Name, | ||
armstorage.BlobContainer{ | ||
ContainerProperties: &armstorage.ContainerProperties{ | ||
PublicAccess: to.Ptr(armstorage.PublicAccessNone), | ||
Metadata: s.getBucketTags(bucket), | ||
}, | ||
}, | ||
nil, | ||
) | ||
if err != nil { | ||
s.logger.Error(err, fmt.Sprintf("failed to create storage container %s", bucket.Spec.Name)) | ||
return err | ||
} | ||
s.logger.Info(fmt.Sprintf("storage container %s created", bucket.Spec.Name)) | ||
} else { | ||
_, err := s.blobContainerClient.Update( | ||
ctx, | ||
s.cluster.GetResourceGroup(), | ||
storageAccountName, | ||
bucket.Spec.Name, | ||
armstorage.BlobContainer{ | ||
ContainerProperties: &armstorage.ContainerProperties{ | ||
Metadata: s.getBucketTags(bucket), | ||
}, | ||
}, | ||
nil, | ||
) | ||
if err != nil { | ||
s.logger.Error(err, fmt.Sprintf("failed to update storage container %s", bucket.Spec.Name)) | ||
return err | ||
} | ||
s.logger.Info(fmt.Sprintf("storage container %s updated", bucket.Spec.Name)) | ||
} | ||
|
||
return nil | ||
} |
106 changes: 106 additions & 0 deletions
106
internal/pkg/service/objectstorage/cloud/azure/privateendpoint.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,106 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns" | ||
|
||
"github.com/giantswarm/object-storage-operator/api/v1alpha1" | ||
) | ||
|
||
var subnetID = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s" | ||
|
||
func (s AzureObjectStorageAdapter) upsertPrivateEndpoint(ctx context.Context, bucket *v1alpha1.Bucket, storageAccountName string) (*armnetwork.PrivateEndpoint, error) { | ||
// Create or Update Private endpoint | ||
pollersResp, err := s.privateEndpointsClient.BeginCreateOrUpdate( | ||
ctx, | ||
s.cluster.GetResourceGroup(), | ||
bucket.Spec.Name, | ||
armnetwork.PrivateEndpoint{ | ||
Location: to.Ptr(s.cluster.GetRegion()), | ||
Properties: &armnetwork.PrivateEndpointProperties{ | ||
CustomNetworkInterfaceName: to.Ptr(fmt.Sprintf("%s-nodes-nic", bucket.Spec.Name)), | ||
PrivateLinkServiceConnections: []*armnetwork.PrivateLinkServiceConnection{ | ||
{ | ||
Name: to.Ptr(bucket.Spec.Name), | ||
Properties: &armnetwork.PrivateLinkServiceConnectionProperties{ | ||
PrivateLinkServiceID: to.Ptr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Storage/storageAccounts/%s", s.cluster.GetSubscriptionID(), s.cluster.GetResourceGroup(), storageAccountName)), | ||
GroupIDs: []*string{to.Ptr("blob")}, | ||
}, | ||
}, | ||
}, | ||
Subnet: &armnetwork.Subnet{ | ||
ID: to.Ptr(s.subnetID()), | ||
}, | ||
}, | ||
Tags: s.getBucketTags(bucket), | ||
}, | ||
nil, | ||
) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := pollersResp.PollUntilDone(ctx, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &resp.PrivateEndpoint, nil | ||
} | ||
|
||
func (s AzureObjectStorageAdapter) upsertPrivateZone(ctx context.Context, bucket *v1alpha1.Bucket) (*armprivatedns.PrivateZone, error) { | ||
pollersResp, err := s.privateZonesClient.BeginCreateOrUpdate( | ||
ctx, | ||
s.cluster.GetResourceGroup(), | ||
bucket.Spec.Name, | ||
armprivatedns.PrivateZone{ | ||
Location: to.Ptr(s.cluster.GetRegion()), | ||
Tags: s.getBucketTags(bucket), | ||
}, | ||
nil, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := pollersResp.PollUntilDone(ctx, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp.PrivateZone, nil | ||
} | ||
|
||
func (s AzureObjectStorageAdapter) upsertVirtualNetworkLink(ctx context.Context, bucket *v1alpha1.Bucket) (*armprivatedns.VirtualNetworkLink, error) { | ||
pollersResp, err := s.virtualNetworkLinksClient.BeginCreateOrUpdate( | ||
ctx, | ||
s.cluster.GetResourceGroup(), | ||
bucket.Spec.Name, | ||
bucket.Spec.Name, | ||
armprivatedns.VirtualNetworkLink{ | ||
Location: to.Ptr(s.cluster.GetRegion()), | ||
Properties: &armprivatedns.VirtualNetworkLinkProperties{ | ||
RegistrationEnabled: to.Ptr(true), | ||
VirtualNetwork: &armprivatedns.SubResource{ | ||
ID: to.Ptr(s.subnetID()), | ||
}, | ||
}, | ||
Tags: s.getBucketTags(bucket), | ||
}, | ||
nil, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := pollersResp.PollUntilDone(ctx, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp.VirtualNetworkLink, nil | ||
} | ||
|
||
func (s AzureObjectStorageAdapter) subnetID() string { | ||
return fmt.Sprintf(subnetID, s.cluster.GetSubscriptionID(), s.cluster.GetResourceGroup(), s.cluster.GetVNetName(), "node-subnet") | ||
} |
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.