Skip to content

Commit

Permalink
Merge branch 'main' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchen8911 authored May 10, 2024
2 parents d34e89d + f72e040 commit 4399b0f
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 26 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on: workflow_dispatch

env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: make build

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,priority=100,prefix=,suffix=,format=short
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bin
/venv
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
run:
timeout: 5m

linters:
enable:
- errcheck
- goimports
- gosec
- gosimple
- govet
- ineffassign
- megacheck
- staticcheck
- typecheck
- unused

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Knavigator is a project designed to analyze, optimize, and compare scheduling sy

The term "knavigator" is derived from "navigator," with a silent "k" prefix representing "kubernetes." Much like a navigator, this initiative assists in charting a secure route and steering clear of obstacles within the cluster.

Knavigator interfaces with Kubernetes clusters to manage tasks such as manupulating with Kubernetes objects, evaluating PromQL queries, as well as executing specific operations.
Knavigator interfaces with Kubernetes clusters to manage tasks such as manipulating with Kubernetes objects, evaluating PromQL queries, as well as executing specific operations.

Knavigator can operate both outside and inside a Kubernetes cluster, leveraging the Kubernetes API for task management.

Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func New(data []byte) (*TaskConfig, error) {

// NewFromFile populates test config from YAML file
func NewFromFile(path string) (*TaskConfig, error) {
path = filepath.Clean(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/check_object_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (task *CheckObjTask) checkStateAsync(ctx context.Context, name string, info
}
}

// checkState validates state conformance and removes object name from the map if succeded
// checkState validates state conformance and removes object name from the map if succeeded
func (task *CheckObjTask) checkState(ctx context.Context, name string, info *ObjInfo, nameMap *utils.SyncMap) error {
cr, err := task.client.Resource(info.GVR).Namespace(info.Namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/k8s_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GetK8sConfig(log logr.Logger, kubeConfigPath, kubectx string) (*rest.Config
if err != nil {
return nil, err
}
//update cert file location if needed
// update cert file location if needed
for _, info := range config.AuthInfos {
if len(info.LocationOfOrigin) != 0 {
dir := filepath.Dir(info.LocationOfOrigin)
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/k8s_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func TestGetK8sConfig(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
os.Unsetenv("KUBECONFIG")
_ = os.Unsetenv("KUBECONFIG")
if len(tc.envCfg) != 0 {
f, err := os.CreateTemp("", "test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer func() { _ = os.Remove(f.Name()) }()

_, err = f.Write([]byte(tc.envCfg))
require.NoError(t, err)
Expand All @@ -127,7 +127,7 @@ func TestGetK8sConfig(t *testing.T) {
if len(tc.kubeCfg) != 0 {
f, err := os.CreateTemp("", "test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer func() { _ = os.Remove(f.Name()) }()

_, err = f.Write([]byte(tc.kubeCfg))
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions resources/templates/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ spec:
template:
metadata:
annotations:
orgName: {{or .orgName "my-org" }}
teamName: {{or .teamName "my-team" }}
userName: "{{or .userName "my-user"}}"
orgName: {{or .orgName "my-org"}}
teamName: {{or .teamName "my-team"}}
userName: {{or .userName "my-user"}}
labels:
obj-name: test
instance: {{.instance}}
Expand Down
4 changes: 2 additions & 2 deletions resources/templates/k8s/failed-job.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: batch/v1
kind: Job
kind: Job
metadata:
name: "{{._NAME_}}"
namespace: "{{.namespace}}"
spec:
backoffLimit: {{.backoffLimit}}
completions: {{.completions}}
completions: {{.completions}}
parallelism: {{.parallelism}}
completionMode: {{.completionMode}}
template:
Expand Down
4 changes: 2 additions & 2 deletions resources/templates/k8s/job.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: batch/v1
kind: Job
kind: Job
metadata:
name: "{{._NAME_}}"
namespace: "{{.namespace}}"
spec:
backoffLimit: {{.backoffLimit}}
completions: {{.completions}}
completions: {{.completions}}
parallelism: {{.parallelism}}
completionMode: {{.completionMode}}
template:
Expand Down
12 changes: 6 additions & 6 deletions resources/templates/k8s/jobset-with-driver.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: jobset.x-k8s.io/v1alpha2
kind: JobSet
kind: JobSet
metadata:
name: "{{._NAME_}}"
namespace: "{{.namespace}}"
spec:
# We want to declare our JobSet successful if workers finish.
# If workers finish we should clean up the remaining replicatedJobs.
# We want to declare our JobSet successful if workers finish.
# If workers finish we should clean up the remaining replicatedJobs.
successPolicy:
operator: All
targetReplicatedJobs:
Expand All @@ -16,7 +16,7 @@ spec:
template:
spec:
# Set backoff limit to 0 so job will immediately fail if any pod fails.
backoffLimit: 0
backoffLimit: 0
completions: 1
parallelism: 1
template:
Expand All @@ -25,11 +25,11 @@ spec:
- name: driver
image: {{.image}}
- name: workers
replicas: {{.replicas}}
replicas: {{.replicas}}
template:
spec:
backoffLimit: {{.backoffLimit}}
completions: {{.completions}}
completions: {{.completions}}
parallelism: {{.parallelism}}
completionMode: {{.completionMode}}
template:
Expand Down
10 changes: 5 additions & 5 deletions resources/templates/k8s/jobset.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
apiVersion: jobset.x-k8s.io/v1alpha2
kind: JobSet
kind: JobSet
metadata:
name: "{{._NAME_}}"
namespace: "{{.namespace}}"
spec:
# We want to declare our JobSet successful if workers finish.
# If workers finish we should clean up the remaining replicatedJobs.
# We want to declare our JobSet successful if workers finish.
# If workers finish we should clean up the remaining replicatedJobs.
successPolicy:
operator: All
targetReplicatedJobs:
- workers
replicatedJobs:
- name: workers
replicas: {{.replicas}}
replicas: {{.replicas}}
template:
spec:
backoffLimit: {{.backoffLimit}}
completions: {{.completions}}
completions: {{.completions}}
parallelism: {{.parallelism}}
completionMode: {{.completionMode}}
template:
Expand Down
2 changes: 1 addition & 1 deletion resources/tests/k8s/test-failed-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ tasks:
- id: status
type: CheckPod
params:
refTaskId: job
refTaskId: job
status: Failed
timeout: 10s
2 changes: 1 addition & 1 deletion resources/tests/volcano/test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tasks:
pods:
range:
pattern: "{{._NAME_}}-test-{{._INDEX_}}"
ranges: ["0-1"]
ranges: ["0-1"]
- id: status
type: CheckPod
params:
Expand Down

0 comments on commit 4399b0f

Please sign in to comment.