Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Azure): Incorporate azure resources #830

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,15 @@ k8s_codegen:
@rm -rf $(K8S_CODE_GENERATOR)

k8s_codegen_operator:
@tar zxvf $(K8S_CODE_GENERATOR).tar.gz -C ./../ --no-same-owner
@tar zxvf $(K8S_CODE_GENERATOR).tar.gz --no-same-owner
@chmod +x $(K8S_CODE_GENERATOR)/generate-groups.sh
@$(K8S_CODE_GENERATOR)/generate-groups.sh all $(OPERATOR_KUBERNETES_PKG)/client \
$(OPERATOR_KUBERNETES_PKG)/apis "netapp:v1" -h ./../hack/boilerplate.go.txt
$(OPERATOR_KUBERNETES_PKG)/apis "netapp:v1" -h ./hack/boilerplate.go.txt
@rm -rf $(K8S_CODE_GENERATOR)
@rm -rf ./operator/controllers/orchestrator/client/*
@mv $(OPERATOR_KUBERNETES_PKG)/client/* ./operator/controllers/orchestrator/client/
@rm -rf ./operator/controllers/orchestrator/apis/netapp/v1/zz_generated.deepcopy.go
@mv $(OPERATOR_KUBERNETES_PKG)/apis/netapp/v1/zz_generated.deepcopy.go ./operator/controllers/orchestrator/apis/netapp/v1/

mocks:
@go install github.com/golang/mock/mockgen@v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions cli/k8s_client/k8s_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const (

// CRD Finalizer name
TridentFinalizer = "trident.netapp.io"

CloudProviderAzure = "Azure"
)

type LogLineCallback func(string)
Expand Down
1 change: 1 addition & 0 deletions cli/k8s_client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ type DeploymentYAMLArguments struct {
ServiceAccountName string `json:"serviceAccountName"`
ImagePullPolicy string `json:"imagePullPolicy"`
EnableForceDetach bool `json:"enableForceDetach"`
CloudProvider string `json:"cloudProvider"`
ACPImage string `json:"acpImage"`
EnableACP bool `json:"enableACP"`
}
Expand Down
13 changes: 13 additions & 0 deletions cli/k8s_client/yaml_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ func GetCSIDeploymentYAML(args *DeploymentYAMLArguments) string {
autosupportDebugLine = "#" + autosupportDebugLine
}

if strings.EqualFold(args.CloudProvider, CloudProviderAzure) {
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{AZURE_CREDENTIAL_FILE_ENV}", "- name: AZURE_CREDENTIAL_FILE\n value: /etc/kubernetes/azure.json")
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{AZURE_CREDENTIAL_FILE_VOLUME}", "- name: azure-cred\n hostPath:\n path: /etc/kubernetes\n type: DirectoryOrCreate")
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{AZURE_CREDENTIAL_FILE_VOLUME_MOUNT}", "- name: azure-cred\n mountPath: /etc/kubernetes")
} else {
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{AZURE_CREDENTIAL_FILE_ENV}", "")
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{AZURE_CREDENTIAL_FILE_VOLUME}", "")
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{AZURE_CREDENTIAL_FILE_VOLUME_MOUNT}", "")
}

if args.EnableACP {
enableACP = "- \"-enable_acp\""
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{ACP_YAML}", acpContainerYAMLTemplate)
Expand Down Expand Up @@ -572,12 +582,14 @@ spec:
value: unix://plugin/csi.sock
- name: TRIDENT_SERVER
value: "{IP_LOCALHOST}:8000"
{AZURE_CREDENTIAL_FILE_ENV}
volumeMounts:
- name: socket-dir
mountPath: /plugin
- name: certs
mountPath: /certs
readOnly: true
{AZURE_CREDENTIAL_FILE_VOLUME_MOUNT}
- name: trident-autosupport
image: {AUTOSUPPORT_IMAGE}
imagePullPolicy: {IMAGE_PULL_POLICY}
Expand Down Expand Up @@ -703,6 +715,7 @@ spec:
emptyDir:
medium: ""
sizeLimit: 1Gi
{AZURE_CREDENTIAL_FILE_VOLUME}
`

func GetCSIDaemonSetYAMLWindows(args *DaemonsetYAMLArguments) string {
Expand Down
35 changes: 35 additions & 0 deletions cli/k8s_client/yaml_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ghodss/yaml"
scc "github.com/openshift/api/security/v1"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
pspv1beta1 "k8s.io/api/policy/v1beta1"
csiv1 "k8s.io/api/storage/v1"
Expand Down Expand Up @@ -435,6 +436,40 @@ func TestGetCSIDeploymentYAMLImagePullPolicy(t *testing.T) {
}
}

func TestGetCSIDeploymentYAMLAzure(t *testing.T) {
args := &DeploymentYAMLArguments{
CloudProvider: CloudProviderAzure,
}

yamlData := GetCSIDeploymentYAML(args)
deployment := appsv1.Deployment{}
err := yaml.Unmarshal([]byte(yamlData), &deployment)
if err != nil {
t.Fatalf("expected valid YAML, got %s", yamlData)
}

var envExist, volumeExist, volumeMountExist bool
for _, env := range deployment.Spec.Template.Spec.Containers[0].Env {
if env.Name == "AZURE_CREDENTIAL_FILE" {
envExist = true
break
}
}
for _, volumeMount := range deployment.Spec.Template.Spec.Containers[0].VolumeMounts {
if volumeMount.Name == "azure-cred" {
volumeMountExist = true
break
}
}
for _, volume := range deployment.Spec.Template.Spec.Volumes {
if volume.Name == "azure-cred" {
volumeExist = true
break
}
}
assert.True(t, envExist && volumeExist && volumeMountExist, "expected env var AZURE_CREDENTIAL_FILE to exist")
}

func TestGetCSIDaemonSetYAMLLinux(t *testing.T) {
versions := []string{"1.21.0", "1.23.0", "1.25.0"}

Expand Down
28 changes: 14 additions & 14 deletions frontend/crd/trident_backend_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,20 @@ func (c *TridentCrdController) addBackendConfig(
}).Trace("Adding backend in core.")

backendDetails, err := c.orchestrator.AddBackend(ctx, string(rawJSONData), string(backendConfig.UID))
if err != nil {
if err == nil {
newStatus := tridentv1.TridentBackendConfigStatus{
Message: fmt.Sprintf("Backend '%v' created", backendDetails.Name),
BackendInfo: c.getBackendInfo(ctx, backendDetails.Name, backendDetails.BackendUUID),
Phase: string(tridentv1.PhaseBound),
DeletionPolicy: deletionPolicy,
LastOperationStatus: OperationStatusSuccess,
}

if _, statusErr := c.updateTbcEventAndStatus(ctx, backendConfig, newStatus, "Backend created.",
corev1.EventTypeNormal); statusErr != nil {
err = fmt.Errorf("encountered an error while updating the status: %v", statusErr)
}
} else if !errors.IsReconcileDeferredError(err) {
newStatus := tridentv1.TridentBackendConfigStatus{
Message: fmt.Sprintf("Failed to create backend: %v", err),
BackendInfo: c.getBackendInfo(ctx, "", ""),
Expand All @@ -203,19 +216,6 @@ func (c *TridentCrdController) addBackendConfig(
err = fmt.Errorf("failed to create backend: %v; Also encountered error while updating the status: %v", err,
statusErr)
}
} else {
newStatus := tridentv1.TridentBackendConfigStatus{
Message: fmt.Sprintf("Backend '%v' created", backendDetails.Name),
BackendInfo: c.getBackendInfo(ctx, backendDetails.Name, backendDetails.BackendUUID),
Phase: string(tridentv1.PhaseBound),
DeletionPolicy: deletionPolicy,
LastOperationStatus: OperationStatusSuccess,
}

if _, statusErr := c.updateTbcEventAndStatus(ctx, backendConfig, newStatus, "Backend created.",
corev1.EventTypeNormal); statusErr != nil {
err = fmt.Errorf("encountered an error while updating the status: %v", statusErr)
}
}

return err
Expand Down
33 changes: 24 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/netapp/trident
go 1.21

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/netapp/armnetapp/v4 v4.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.7.1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures v1.1.0
Expand Down Expand Up @@ -58,23 +58,36 @@ require (
k8s.io/mount-utils v0.27.3 // github.com/kubernetes/mount-utils
)

require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1
sigs.k8s.io/cloud-provider-azure v1.27.6
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20230723234811-915dd11ba556
)

require (
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4 v4.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v3 v3.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.1.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect
github.com/Azure/go-armbalancer v0.0.2 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/elastic/go-windows v1.0.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
Expand Down Expand Up @@ -116,21 +129,23 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
golang.org/x/mod v0.9.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
k8s.io/component-base v0.27.3 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading