This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: Move functions and constants in resource utils * chore: Update gitignore to ignore coverage report * test: Add test for resources utils * fix: Fix dependency lock file * test: Add tests for version * feat: Test if configuration is valid before using it * refactor: Rename function in resource * fix: Errors not constants * fix: variable already exists
- Loading branch information
1 parent
7b44409
commit 798a786
Showing
10 changed files
with
225 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,3 +333,6 @@ ASALocalRun/ | |
bin/ | ||
vendor/ | ||
_dist/ | ||
c.out | ||
coverage.html | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package resources | ||
|
||
import ( | ||
v1 "k8s.io/api/core/v1" | ||
k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// AWSVolumeResourceType AWS Volume Resource Type | ||
const AWSVolumeResourceType = "volume" | ||
|
||
// AWSResourcePlatform AWS Resource Platform | ||
const AWSResourcePlatform = "aws" | ||
|
||
func getPersistentVolumeClaim(persistentVolume *v1.PersistentVolume, k8sClient kubernetes.Interface) (*v1.PersistentVolumeClaim, error) { | ||
claimRef := persistentVolume.Spec.ClaimRef | ||
if claimRef == nil { | ||
return nil, nil | ||
} | ||
|
||
pvc, err := k8sClient.CoreV1().PersistentVolumeClaims(claimRef.Namespace).Get(claimRef.Name, metav1.GetOptions{}) | ||
if err != nil && !k8serrors.IsNotFound(err) { | ||
return nil, err | ||
} | ||
return pvc, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
testclient "k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
func TestGetPersistentVolumeClaimWithoutClaimRef(t *testing.T) { | ||
spec := v1.PersistentVolumeSpec{ClaimRef: nil} | ||
pv := v1.PersistentVolume{Spec: spec} | ||
|
||
// Call code | ||
res, err := getPersistentVolumeClaim(&pv, nil) | ||
|
||
assert.Nil(t, res) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestGetPersistentVolumeClaimWithClaimNotFound(t *testing.T) { | ||
claimRef := v1.ObjectReference{Namespace: "test-claim-ref-namespace", Name: "test-claim-ref-name"} | ||
spec := v1.PersistentVolumeSpec{ClaimRef: &claimRef} | ||
pv := v1.PersistentVolume{Spec: spec} | ||
|
||
client := testclient.NewSimpleClientset() | ||
|
||
// Call code | ||
res, err := getPersistentVolumeClaim(&pv, client) | ||
|
||
assert.Nil(t, res) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestGetPersistentVolumeClaimWithClaimFound(t *testing.T) { | ||
claimRefNamespace := "test-claim-ref-namespace" | ||
claimRefName := "test-claim-ref-name" | ||
claimRef := v1.ObjectReference{Namespace: claimRefNamespace, Name: claimRefName} | ||
spec := v1.PersistentVolumeSpec{ClaimRef: &claimRef} | ||
pv := v1.PersistentVolume{Spec: spec} | ||
|
||
// PVC | ||
pvc := &v1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: claimRefName, Namespace: claimRefNamespace}} | ||
|
||
client := testclient.NewSimpleClientset(pvc) | ||
|
||
// Call code | ||
res, err := getPersistentVolumeClaim(&pv, client) | ||
|
||
assert.NotNil(t, res) | ||
assert.Nil(t, err) | ||
assert.Equal(t, pvc, res) | ||
} |
Oops, something went wrong.