Skip to content

Commit

Permalink
Merge branch 'master' into user-identity-mapping-job
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Mar 22, 2024
2 parents 8660f99 + 2b38309 commit a62101e
Show file tree
Hide file tree
Showing 51 changed files with 570 additions and 559 deletions.
44 changes: 44 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Config can be validated before merging: curl -X POST --data-binary @.codecov.yaml https://codecov.io/validate
codecov:
max_report_age: "off" # see https://docs.codecov.io/docs/codecov-yaml#section-expired-reports

# See http://docs.codecov.io/docs/coverage-configuration
coverage:
precision: 2 # 2 = xx.xx%, 0 = xx%
round: down
# For example: 20...60 would result in any coverage less than 20%
# would have a red background. The color would gradually change to
# green approaching 60%. Any coverage over 60% would result in a
# solid green color.
range: "20...60"

# See https://docs.codecov.com/docs/commit-status
status:
# project will give us the diff in the total code coverage between a commit
# and its parent
project:
default:
# Allow the coverage to drop by 1%, and posting a success status.
threshold: 1%
# Patch gives just the coverage of the patch
patch: yes

Check warning on line 24 in .codecov.yaml

View workflow job for this annotation

GitHub Actions / YAML Lint

24:12 [truthy] truthy value should be one of [false, true]
# changes tells us if there are unexpected code coverage changes in other files
# which were not changed by the diff
changes: yes

Check warning on line 27 in .codecov.yaml

View workflow job for this annotation

GitHub Actions / YAML Lint

27:14 [truthy] truthy value should be one of [false, true]

# See http://docs.codecov.io/docs/ignoring-paths
ignore:
- "github/*"
- "cmd/*"
- "make/*"
- "resources/*"
- "test-resources/*"

# See https://docs.codecov.com/docs/pull-request-comments
comment:
layout: "header, diff, tree"
# default = posts once then update, posts new if delete
# once = post once then updates
# new = delete old, post new
# spammy = post new
behavior: "new"
7 changes: 1 addition & 6 deletions .github/workflows/ci-check-gomod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: check
run: |
if [[ -n "$(grep 'replace github.com/kubesaw/.*' go.mod || true)" ]]; then
echo "forbidden replacement in go.mod"
exit 1
fi
uses: codeready-toolchain/toolchain-cicd/gomod-check@master
46 changes: 46 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: ci-build
on:

Check warning on line 2 in .github/workflows/linters.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

2:1 [truthy] truthy value should be one of [false, true]
push:
branches:
- master
tags-ignore:
- '*.*'
pull_request:
branches:
- master

jobs:
golangci:
name: GolangCI Lint
runs-on: ubuntu-latest

steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v4

- name: Lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.56.2
skip-pkg-cache: true
skip-build-cache: true
args: --config=./.golangci.yml --verbose

yammlint:
name: YAML Lint
runs-on: ubuntu-latest

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

- name: Install yamllint
run: pip install yamllint

- name: Lint YAML files
run: yamllint -c .yamllint ./
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
- master
tags-ignore:
- '*.*'
pull_request:
pull_request_target:
types: [ opened, synchronize, reopened, ready_for_review ]

Check warning on line 9 in .github/workflows/test-with-coverage.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

9:13 [brackets] too many spaces inside brackets

Check warning on line 9 in .github/workflows/test-with-coverage.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

9:61 [brackets] too many spaces inside brackets
branches:
- master

Expand All @@ -15,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]

Check warning on line 18 in .github/workflows/test-with-coverage.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

18:14 [brackets] too many spaces inside brackets

Check warning on line 18 in .github/workflows/test-with-coverage.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

18:28 [brackets] too many spaces inside brackets
name: Test on ${{ matrix.os }}
name: Test with coverage

steps:
- name: Install Go
Expand All @@ -25,6 +26,10 @@ jobs:

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0

- name: Cache dependencies
uses: actions/cache@v4
Expand All @@ -49,38 +54,3 @@ jobs:
flags: unittests # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)

golangci:
name: GolangCI Lint
runs-on: ubuntu-latest

steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v4

- name: Lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.56.2
skip-pkg-cache: true
skip-build-cache: true
args: --config=./.golangci.yml --verbose

yammlint:
name: YAML Lint
runs-on: ubuntu-latest

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

- name: Install yamllint
run: pip install yamllint

- name: Lint YAML files
run: yamllint -c .yamllint ./
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @MatousJobanek @xcoulon @alexeykazakov @rajivnathan @ranakan19 @sbryzak @mfrancisc @drpaneas
* @MatousJobanek @xcoulon @alexeykazakov @rajivnathan @ranakan19 @sbryzak @mfrancisc @drpaneas @metlos @fbm3307
10 changes: 5 additions & 5 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func PatchUserSignup(ctx *clicontext.CommandContext, name string, changeUserSign
if err != nil {
return err
}
userSignup, err := GetUserSignup(cl, cfg.SandboxNamespace, name)
userSignup, err := GetUserSignup(cl, cfg.OperatorNamespace, name)
if err != nil {
return err
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func PatchMasterUserRecord(ctx *clicontext.CommandContext, name string, changeMa
if err != nil {
return err
}
mur, err := GetMasterUserRecord(cl, cfg.SandboxNamespace, name)
mur, err := GetMasterUserRecord(cl, cfg.OperatorNamespace, name)
if err != nil {
return err
}
Expand Down Expand Up @@ -188,7 +188,7 @@ func PatchSpace(ctx *clicontext.CommandContext, name string, changeSpace func(*t
if err != nil {
return err
}
space, err := GetSpace(cl, cfg.SandboxNamespace, name)
space, err := GetSpace(cl, cfg.OperatorNamespace, name)
if err != nil {
return err
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func ListSpaceBindings(cl runtimeclient.Client, namespace string, opts ...SpaceB

func GetNSTemplateTier(cfg configuration.ClusterConfig, cl runtimeclient.Client, name string) (*toolchainv1alpha1.NSTemplateTier, error) {
namespacedName := types.NamespacedName{
Namespace: cfg.SandboxNamespace,
Namespace: cfg.OperatorNamespace,
Name: name,
}
obj := &toolchainv1alpha1.NSTemplateTier{}
Expand All @@ -256,7 +256,7 @@ func GetNSTemplateTier(cfg configuration.ClusterConfig, cl runtimeclient.Client,

func GetUserTier(cfg configuration.ClusterConfig, cl runtimeclient.Client, name string) (*toolchainv1alpha1.UserTier, error) {
namespacedName := types.NamespacedName{
Namespace: cfg.SandboxNamespace,
Namespace: cfg.OperatorNamespace,
Name: name,
}
obj := &toolchainv1alpha1.UserTier{}
Expand Down
33 changes: 16 additions & 17 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
func TestNewClientOK(t *testing.T) {
// given
t.Cleanup(gock.OffAll)
gock.New("https://example.com").
gock.New("http://example.com").
Get("api").
Persist().
Reply(200).
BodyString("{}")

// when
cl, err := client.NewClient("cool-token", "https://example.com")
cl, err := client.NewClient("cool-token", "http://example.com")

// then
require.NoError(t, err)
Expand All @@ -56,9 +56,9 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("update is successful", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -75,9 +75,9 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("UserSignup should not be updated", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -93,9 +93,9 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("change UserSignup func returns error", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -111,12 +111,12 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("get of UserSignup fails", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
fakeClient.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error {
return fmt.Errorf("some error")
}
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -131,12 +131,12 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("update of UserSignup fails", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
fakeClient.MockPatch = func(ctx context.Context, obj runtimeclient.Object, patch runtimeclient.Patch, opts ...runtimeclient.PatchOption) error {
return fmt.Errorf("some error")
}
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -157,8 +157,7 @@ func TestPatchUserSignup(t *testing.T) {
newClient := func(_, _ string) (runtimeclient.Client, error) {
return nil, fmt.Errorf("some error")
}
newRESTClient := client.DefaultNewRESTClient
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -177,9 +176,9 @@ func TestUpdateUserSignupLacksPermissions(t *testing.T) {
SetFileConfig(t, Host(NoToken()))

userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -188,7 +187,7 @@ func TestUpdateUserSignupLacksPermissions(t *testing.T) {
}, "updated")

// then
require.EqualError(t, err, "sandbox command failed: the token in your ksctl.yaml file is missing")
require.EqualError(t, err, "ksctl command failed: the token in your ksctl.yaml file is missing")
AssertUserSignupSpec(t, fakeClient, userSignup)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/sandbox_config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path"
)

func EnsureSandboxCliConfigFile() (string, error) {
func EnsureKsctlConfigFile() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/add_space_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ one or more users specified by their MasterUserRecord name. One SpaceBinding wil
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
term := ioutils.NewTerminal(cmd.InOrStdin, cmd.OutOrStdout)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient, client.DefaultNewRESTClient)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient)

return AddSpaceUsers(ctx, spaceName, role, users)
},
Expand All @@ -55,7 +55,7 @@ func AddSpaceUsers(ctx *clicontext.CommandContext, spaceName, role string, users

// get Space
ctx.Println("Checking space...")
space, err := client.GetSpace(cl, cfg.SandboxNamespace, spaceName)
space, err := client.GetSpace(cl, cfg.OperatorNamespace, spaceName)
if err != nil {
return err
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func AddSpaceUsers(ctx *clicontext.CommandContext, spaceName, role string, users
ctx.Println("Checking users...")
spaceBindingsToCreate := []*toolchainv1alpha1.SpaceBinding{}
for _, murName := range usersToAdd {
mur, err := client.GetMasterUserRecord(cl, cfg.SandboxNamespace, murName)
mur, err := client.GetMasterUserRecord(cl, cfg.OperatorNamespace, murName)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit a62101e

Please sign in to comment.