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

✨ add more CI checks #49

Merged
merged 7 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI
on:
pull_request:
branches:
- main
- "release-*"

jobs:
ci-checks:
runs-on: ubuntu-latest
name: CI Checks
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- name: Lint
run: go fmt ./...
- name: Static analysis
run: go vet ./...
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
4 changes: 3 additions & 1 deletion .github/workflows/dco.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: DCO Check
name: dco-check
on:
pull_request:
push:
branches:
- master
- "release-*"
jobs:
check:
name: DCO Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-verifier.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Verifier
name: pr-verifier

on:
# NB: using `pull_request_target` runs this in the context of
Expand All @@ -9,7 +9,7 @@ on:
types: [opened, edited, reopened, synchronize]

jobs:
verify:
verify-pr:
name: verify PR contents
permissions:
checks: write
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/spellcheck_action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Spellcheck Action
name: spellcheck
on:
# So we can trigger manually if needed
workflow_dispatch:
Expand All @@ -12,7 +12,7 @@ on:
- ".github/spellcheck/.wordlist.yml"

jobs:
build:
spellchecker:
name: Spellcheck
runs-on: ubuntu-latest
steps:
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/tag.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <img alt="Logo" width="90px" src="./docs/images/kubeflex-logo.png" style="vertical-align: middle;" /> KubeFlex

A flexible and scalable solution for running Kubernetes control plane APIs.
A flexible and scalable platform for running Kubernetes control plane APIs.

## Goals

Expand All @@ -17,8 +17,9 @@ A flexible and scalable solution for running Kubernetes control plane APIs.

## Installation

You need [kind](https://kind.sigs.k8s.io) installed. Note that a hosting kind cluster
is created automatically by the kubeflex CLI.
[kind](https://kind.sigs.k8s.io) is required. Note that we plan to add support
for other Kube distros. Note that a hosting kind cluster is created automatically
by the kubeflex CLI.

Download the latest kubeflex CLI binary release for your OS/Architecture from the
[release page](https://github.com/kubestellar/kubeflex/releases) and copy it
Expand Down
62 changes: 50 additions & 12 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package client

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"log"
"math/big"
"os"
"os/user"
"testing"
"time"

"github.com/kubestellar/kubeflex/api/v1alpha1"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
//"github.com/kubestellar/kubeflex/api/v1alpha1"
)

var kubeconfig string
Expand All @@ -19,7 +29,24 @@ func TestMain(m *testing.M) {
}
homeDirectory := user.HomeDir
if kubeconfig == "" {
os.Setenv("KUBECONFIG", homeDirectory+"/.kube/config")
kubeconfig = homeDirectory + "/.kube/config"
if _, err := os.Stat(kubeconfig); os.IsNotExist(err) {
// Create a new configuration file with some default contents
config := clientcmdapi.NewConfig()
config.Clusters["my-cluster"] = &api.Cluster{
Server: "https://example.com",
CertificateAuthorityData: []byte(generateTestCA()),
}
config.Contexts["my-context"] = &api.Context{
Cluster: "my-cluster",
AuthInfo: "my-user",
}
config.AuthInfos["my-user"] = &api.AuthInfo{
Token: "MY_TOKEN",
}
config.CurrentContext = "my-context"
clientcmd.WriteToFile(*config, kubeconfig)
}
}

code := m.Run()
Expand All @@ -34,16 +61,27 @@ func TestGetClientSet(t *testing.T) {
}
}

func TestGetClient(t *testing.T) {
c := GetClient(kubeconfig)
if c == nil {
t.Error("Expected client to not be nil")
func generateTestCA() string {
privKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
panic(err)
}

// Make sure the custom type has been added to the scheme
x := *c
scheme := x.Scheme()
if err := v1alpha1.AddToScheme(scheme); err != nil {
t.Errorf("Failed to add custom type to scheme: %v", err)
template := x509.Certificate{
SerialNumber: big.NewInt(1658),
Subject: pkix.Name{CommonName: "example.com"},
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(1, 0, 0),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
certBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &privKey.PublicKey, privKey)
if err != nil {
panic(err)
}
certPEM := pem.EncodeToMemory(&pem.Block{
Type: "CERTIFICATE",
Bytes: certBytes,
})
return string(certPEM)
}