-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from FabianKramm/main
feat: improve kuberentes provider & k8s e2e tests
- Loading branch information
Showing
28 changed files
with
4,777 additions
and
120 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 |
---|---|---|
|
@@ -11,6 +11,10 @@ on: | |
- "e2e/**_test.go" # include test files in e2e again | ||
- ".github/workflows/e2e-tests.yaml" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
GO111MODULE: on | ||
GOFLAGS: -mod=vendor | ||
|
@@ -28,14 +32,27 @@ jobs: | |
with: | ||
go-version: 1.19 | ||
|
||
- name: Set up kind k8s cluster | ||
uses: engineerd/[email protected] | ||
with: | ||
version: "v0.20.0" | ||
image: kindest/node:v1.27.3 | ||
|
||
- name: Testing kind cluster set-up | ||
run: | | ||
set -x | ||
kubectl cluster-info | ||
kubectl get pods -n kube-system -v 10 | ||
echo "kubectl config current-context:" $(kubectl config current-context) | ||
echo "KUBECONFIG env var:" ${KUBECONFIG} | ||
- name: Build binary and copy to the E2E directory | ||
working-directory: ./e2e | ||
run: | | ||
chmod +x ../hack/build-e2e.sh | ||
BUILDDIR=bin SRCDIR=".." ../hack/build-e2e.sh | ||
- name: E2E test | ||
working-directory: ./e2e | ||
run: | | ||
sudo go test -v -ginkgo.v -timeout 3600s | ||
sudo KUBECONFIG=/home/runner/.kube/config go test -v -ginkgo.v -timeout 3600s |
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,4 @@ | ||
{ | ||
"name": "Go", | ||
"image": "mcr.microsoft.com/devcontainers/go:0-1.19-bullseye" | ||
} |
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,90 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/loft-sh/log" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
) | ||
|
||
const ( | ||
limitsPrefix = "limits." | ||
) | ||
|
||
func parseResources(resourceString string, log log.Logger) corev1.ResourceRequirements { | ||
if resourceString == "" { | ||
return corev1.ResourceRequirements{} | ||
} | ||
|
||
resourcesSplitted := strings.Split(resourceString, ",") | ||
requests := corev1.ResourceList{} | ||
limits := corev1.ResourceList{} | ||
for _, resourceName := range resourcesSplitted { | ||
resourceName = strings.TrimSpace(resourceName) | ||
|
||
// requests | ||
if strings.HasPrefix(corev1.DefaultResourceRequestsPrefix, resourceName) { | ||
strippedResource := strings.TrimPrefix(corev1.DefaultResourceRequestsPrefix, resourceName) | ||
name, quantity, err := parseResource(strippedResource) | ||
if err != nil { | ||
log.Error(err.Error()) | ||
continue | ||
} | ||
|
||
requests[corev1.ResourceName(name)] = quantity | ||
} | ||
|
||
// limits | ||
if strings.HasPrefix(limitsPrefix, resourceName) { | ||
strippedResource := strings.TrimPrefix(limitsPrefix, resourceName) | ||
name, quantity, err := parseResource(strippedResource) | ||
if err != nil { | ||
log.Error(err.Error()) | ||
continue | ||
} | ||
|
||
limits[corev1.ResourceName(name)] = quantity | ||
} | ||
} | ||
|
||
return corev1.ResourceRequirements{ | ||
Limits: limits, | ||
Requests: requests, | ||
} | ||
} | ||
|
||
func parseLabels(str string) (map[string]string, error) { | ||
if str == "" { | ||
return nil, nil | ||
} | ||
|
||
labels := strings.Split(str, ",") | ||
retMap := map[string]string{} | ||
for _, label := range labels { | ||
label = strings.TrimSpace(label) | ||
splitted := strings.SplitN(label, "=", 2) | ||
if len(splitted) != 2 { | ||
return nil, fmt.Errorf("invalid label '%s', expected format label=value", label) | ||
} | ||
|
||
retMap[splitted[0]] = splitted[1] | ||
} | ||
|
||
return retMap, nil | ||
} | ||
|
||
func parseResource(resourceName string) (string, resource.Quantity, error) { | ||
splittedResource := strings.SplitN(resourceName, "=", 2) | ||
if len(splittedResource) != 2 { | ||
return "", resource.Quantity{}, fmt.Errorf("error parsing resource %s: expected form resource=quantity", resourceName) | ||
} | ||
|
||
quantity, err := resource.ParseQuantity(splittedResource[1]) | ||
if err != nil { | ||
return "", resource.Quantity{}, fmt.Errorf("error parsing resource %s: %w", resourceName, err) | ||
} | ||
|
||
return splittedResource[0], quantity, 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
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
Oops, something went wrong.