Skip to content

Commit

Permalink
Merge pull request rancher#270 from KevinJoiner/wrangler-ci
Browse files Browse the repository at this point in the history
Wrangler CI
  • Loading branch information
mattfarina authored Feb 21, 2023
2 parents 76adc44 + 707ef06 commit d73a46f
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 32 deletions.
55 changes: 47 additions & 8 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
---
kind: pipeline
type: docker
name: fossa

steps:
- name: fossa
image: rancher/drone-fossa:latest
settings:
api_key:
from_secret: FOSSA_API_KEY
when:
instance:
- drone-publish.rancher.io
- name: fossa
image: rancher/drone-fossa:latest
settings:
api_key:
from_secret: FOSSA_API_KEY
when:
instance:
- drone-publish.rancher.io

---
kind: pipeline
type: docker
name: amd64

platform:
os: linux
arch: amd64

steps:
- name: test
image: registry.suse.com/bci/golang:1.19
commands:
- zypper -n install tar gzip
- "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.1;"
- ./scripts/ci
volumes:
- name: docker
path: /var/run/docker.sock

---
kind: pipeline
type: docker
name: arm64

platform:
os: linux
arch: arm64

steps:
- name: test
image: registry.suse.com/bci/golang:1.19
commands:
- ./scripts/ci
volumes:
- name: docker
path: /var/run/docker.sock
1 change: 0 additions & 1 deletion pkg/apply/desiredset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type desiredSet struct {
noDeleteGVK map[schema.GroupVersionKind]struct{}
setID string
objs *objectset.ObjectSet
codeVersion string
owner runtime.Object
injectors []injectors.ConfigInjector
ratelimitingQps float32
Expand Down
2 changes: 1 addition & 1 deletion pkg/apply/desiredset_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (o *desiredSet) debugID() string {
func (o *desiredSet) collect(objList []runtime.Object) objectset.ObjectByGVK {
result := objectset.ObjectByGVK{}
for _, obj := range objList {
result.Add(obj)
_, _ = result.Add(obj)
}
return result
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/apply/desiredset_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"testing"

"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic/fake"
k8stesting "k8s.io/client-go/testing"
)
Expand All @@ -28,8 +28,10 @@ func Test_multiNamespaceList(t *testing.T) {
}},
"ns3": {Items: []unstructured.Unstructured{}},
}

baseClient := fake.NewSimpleDynamicClient(runtime.NewScheme())
s := runtime.NewScheme()
err := appsv1.SchemeBuilder.AddToScheme(s)
assert.NoError(t, err, "Failed to build schema.")
baseClient := fake.NewSimpleDynamicClient(s)
baseClient.PrependReactor("list", "*", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
if strings.Contains(action.GetNamespace(), "error") {
return true, nil, errors.New("simulated failure")
Expand Down Expand Up @@ -91,7 +93,7 @@ func Test_multiNamespaceList(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var calls int
err := multiNamespaceList(context.TODO(), tt.args.namespaces, baseClient.Resource(schema.GroupVersionResource{}), labels.NewSelector(), func(obj unstructured.Unstructured) {
err := multiNamespaceList(context.TODO(), tt.args.namespaces, baseClient.Resource(appsv1.SchemeGroupVersion.WithResource("deployments")), labels.NewSelector(), func(obj unstructured.Unstructured) {
calls += 1
})

Expand Down
1 change: 0 additions & 1 deletion pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ func getValue(obj interface{}, name ...string) reflect.Value {
t := v.Type()
if t.Kind() == reflect.Ptr {
v = v.Elem()
t = v.Type()
}

field := v.FieldByName(name[0])
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller-gen/args/groupversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (
func TestScan(t *testing.T) {
cwd, _ := os.Getwd()
fmt.Println(cwd)
ScanDirectory("./testdata")
_, _ = ScanDirectory("./testdata")
}
7 changes: 3 additions & 4 deletions pkg/controller-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllergen
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -46,7 +45,7 @@ func Run(opts cgargs.Options) {
genericArgs.InputDirs = parseTypes(customArgs)

if genericArgs.OutputBase == "./" { //go modules
tempDir, err := ioutil.TempDir("", "")
tempDir, err := os.MkdirTemp("", "")
if err != nil {
return
}
Expand Down Expand Up @@ -123,7 +122,7 @@ func sourcePackagePath(customArgs *cgargs.CustomArgs, pkgName string) string {
return pkg
}

//until k8s code-gen supports gopath
// until k8s code-gen supports gopath
func copyGoPathToModules(customArgs *cgargs.CustomArgs) error {

pathsToCopy := map[string]bool{}
Expand All @@ -137,7 +136,7 @@ func copyGoPathToModules(customArgs *cgargs.CustomArgs) error {
pkg := sourcePackagePath(customArgs, customArgs.Package)
pathsToCopy[pkg] = true

for pkg, _ := range pathsToCopy {
for pkg := range pathsToCopy {
if _, err := os.Stat(pkg); os.IsNotExist(err) {
continue
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/data/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"
"unicode"

"golang.org/x/text/cases"
"golang.org/x/text/language"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand Down Expand Up @@ -235,7 +237,8 @@ func EncodeToMap(obj interface{}) (map[string]interface{}, error) {
func ToJSONKey(str string) string {
parts := strings.Split(str, "_")
for i := 1; i < len(parts); i++ {
parts[i] = strings.Title(parts[i])
caser := cases.Title(language.English)
parts[i] = caser.String(parts[i])
}

return strings.Join(parts, "")
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *Factory) setControllerFactoryWithLock() error {

func (c *Factory) Sync(ctx context.Context) error {
if c.cacheFactory != nil {
c.cacheFactory.Start(ctx)
_ = c.cacheFactory.Start(ctx)
c.cacheFactory.WaitForCacheSync(ctx)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (g *Git) gitCmd(output io.Writer, args ...string) error {

cmd.Env = append(cmd.Env, "GIT_SSH_COMMAND="+fmt.Sprintf("ssh -o UserKnownHostsFile=%s", f.Name()))
} else {
cmd.Env = append(cmd.Env, "GIT_SSH_COMMAND="+fmt.Sprintf("ssh -o StrictHostKeyChecking=accept-new"))
cmd.Env = append(cmd.Env, "GIT_SSH_COMMAND="+"ssh -o StrictHostKeyChecking=accept-new")
}
cmd.Env = append(cmd.Env, "GIT_TERMINAL_PROMPT=0")

Expand Down
3 changes: 1 addition & 2 deletions pkg/kubeconfig/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kubeconfig

import (
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -51,7 +50,7 @@ func GetLoadingRules(kubeConfig string) *clientcmd.ClientConfigLoadingRules {

func canRead(files []string) (result []string) {
for _, f := range files {
_, err := ioutil.ReadFile(f)
_, err := os.ReadFile(f)
if err == nil {
result = append(result, f)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schemas/mappers/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (m Move) ModifySchema(s *types.Schema, schemas *types.Schemas) error {
return fmt.Errorf("failed to find field %s on schema %s", m.From, s.ID)
}

toSchema, toFieldName, _, ok, err := getField(s, schemas, m.To)
toSchema, toFieldName, _, _, err := getField(s, schemas, m.To)
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/schemas/reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ func (s *Schemas) processFieldsMappers(t reflect.Type, fieldName string, schema
parts := strings.SplitN(fieldMapper, "=", 2)
name = parts[0]
if len(parts) == 2 {
for _, opt := range strings.Split(parts[1], "|") {
opts = append(opts, opt)
}
opts = append(opts, strings.Split(parts[1], "|")...)
}

factory, ok := s.fieldMappers[name]
Expand Down
2 changes: 0 additions & 2 deletions pkg/summary/summarized.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (in *SummarizedObjectList) DeepCopyInto(out *SummarizedObjectList) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}

func (in *SummarizedObjectList) DeepCopy() *SummarizedObjectList {
Expand All @@ -78,7 +77,6 @@ func (in *SummarizedObject) DeepCopyInto(out *SummarizedObject) {
out.TypeMeta = in.TypeMeta
out.ObjectMeta = *in.ObjectMeta.DeepCopy()
out.Summary = *in.Summary.DeepCopy()
return
}

func (in *SummarizedObject) DeepCopy() *SummarizedObject {
Expand Down
5 changes: 4 additions & 1 deletion pkg/webhook/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func (r *Router) sendError(rw http.ResponseWriter, review *v1.AdmissionReview, e

func writeResponse(rw http.ResponseWriter, review *v1.AdmissionReview) {
rw.Header().Set("Content-Type", "application/json")
json.NewEncoder(rw).Encode(review)
err := json.NewEncoder(rw).Encode(review)
if err != nil {
logrus.Errorf("Failed to write response: %s", err)
}
}

// ServeHTTP inspects the http.Request and calls the Admit function on all matching handlers.
Expand Down
30 changes: 30 additions & 0 deletions scripts/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! /bin/bash
set -e

cd $(dirname $0)/..
PATH=${PATH}:./bin
echo "Validating"

if ! command -v golangci-lint; then
echo Skipping validation: no golangci-lint available
else
echo Running: golangci-lint
golangci-lint run
fi

echo Running: go generate
go generate ./...

echo Tidying up modules
go mod tidy

echo Verifying modules
go mod verify

if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
echo "Encountered dirty repo!"
exit 1
fi

echo "Running Test"
go test ./...

0 comments on commit d73a46f

Please sign in to comment.