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 14 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 @@ -417,11 +417,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/[email protected]
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"`
}

type DaemonsetYAMLArguments struct {
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 @@ -433,6 +433,16 @@ func GetCSIDeploymentYAML(args *DeploymentYAMLArguments) string {
autosupportDebugLine = "#" + autosupportDebugLine
}

if 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}", "")
}

deploymentYAML = strings.ReplaceAll(deploymentYAML, "{TRIDENT_IMAGE}", args.TridentImage)
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{DEPLOYMENT_NAME}", args.DeploymentName)
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{CSI_SIDECAR_REGISTRY}", args.ImageRegistry)
Expand Down Expand Up @@ -543,12 +553,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 @@ -672,6 +684,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 @@ -437,6 +438,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
63 changes: 37 additions & 26 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.19

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1
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.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures v1.1.0
Expand Down Expand Up @@ -39,45 +39,54 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/afero v1.9.5
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/vishvananda/netlink v1.1.0
github.com/zcalusic/sysinfo v0.9.6-0.20220805135214-99e836ba64f2
go.uber.org/multierr v1.11.0 // github.com/uber-go/multierr
golang.org/x/crypto v0.8.0 // github.com/golang/crypto
golang.org/x/net v0.9.0 // github.com/golang/net
golang.org/x/crypto v0.10.0 // github.com/golang/crypto
golang.org/x/net v0.10.0 // github.com/golang/net
golang.org/x/oauth2 v0.7.0 // github.com/golang/oauth2
golang.org/x/sys v0.7.0 // github.com/golang/sys
golang.org/x/text v0.9.0 // github.com/golang/text
golang.org/x/sys v0.9.0 // github.com/golang/sys
golang.org/x/text v0.10.0 // github.com/golang/text
golang.org/x/time v0.3.0 // github.com/golang/time
google.golang.org/grpc v1.54.0 // github.com/grpc/grpc-go
k8s.io/api v0.26.3 // github.com/kubernetes/api
k8s.io/api v0.27.1 // github.com/kubernetes/api
k8s.io/apiextensions-apiserver v0.26.3 // github.com/kubernetes/apiextensions-apiserver
k8s.io/apimachinery v0.26.3 // github.com/kubernetes/apimachinery
k8s.io/client-go v0.26.3 // github.com/kubernetes/client-go
k8s.io/apimachinery v0.27.1 // github.com/kubernetes/apimachinery
k8s.io/client-go v0.27.1 // github.com/kubernetes/client-go
k8s.io/mount-utils v0.26.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.5
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20230614113418-76168d52887e
)

require (
cloud.google.com/go/compute v1.15.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // 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/v4 v4.2.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.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/loads v0.21.1 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -115,22 +124,24 @@ 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.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/tools v0.6.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.9.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.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/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/component-base v0.27.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // 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
)
Loading