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

Updated dapper files #418

Merged
merged 2 commits into from
Nov 28, 2022
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
17 changes: 5 additions & 12 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM golang:1.13.4-alpine3.10
FROM registry.suse.com/bci/golang:1.17

ARG DAPPER_HOST_ARCH
ENV ARCH $DAPPER_HOST_ARCH

RUN apk -U add bash git gcc musl-dev docker vim less file curl wget ca-certificates
RUN go get -d golang.org/x/lint/golint && \
git -C /go/src/golang.org/x/lint/golint checkout -b current 06c8688daad7faa9da5a0c2f163a3d14aac986ca && \
go install golang.org/x/lint/golint && \
rm -rf /go/src /go/pkg
RUN mkdir -p /go/src/golang.org/x && \
cd /go/src/golang.org/x && git clone https://github.com/golang/tools && \
git -C /go/src/golang.org/x/tools checkout -b current aa82965741a9fecd12b026fbb3d3c6ed3231b8f8 && \
go install golang.org/x/tools/cmd/goimports
ARG CACHEBUST=1
RUN zypper -n up && \
zypper -n in git docker vim curl wget
RUN rm -rf /go/src /go/pkg
RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.46.2; \
fi

ENV GO111MODULE off
Expand Down
8 changes: 4 additions & 4 deletions api/writer/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type HTMLResponseWriter struct {
}

func (h *HTMLResponseWriter) start(apiContext *types.APIContext, code int, obj interface{}) {
AddCommonResponseHeader(apiContext)
_ = AddCommonResponseHeader(apiContext)
apiContext.Response.Header().Set("content-type", "text/html")
apiContext.Response.Header().Set("X-Frame-Options", "SAMEORIGIN")
apiContext.Response.WriteHeader(code)
Expand All @@ -68,10 +68,10 @@ func (h *HTMLResponseWriter) Write(apiContext *types.APIContext, code int, obj i
headerString = strings.Replace(headerString, "%JSURL%", jsurl, 1)
headerString = strings.Replace(headerString, "%CSSURL%", cssurl, 1)

apiContext.Response.Write([]byte(headerString))
h.Body(apiContext, apiContext.Response, obj)
_, _ = apiContext.Response.Write([]byte(headerString))
_ = h.Body(apiContext, apiContext.Response, obj)
if schemaSchema != nil {
apiContext.Response.Write(end)
_, _ = apiContext.Response.Write(end)
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/writer/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ type EncodingResponseWriter struct {
}

func (j *EncodingResponseWriter) start(apiContext *types.APIContext, code int, obj interface{}) {
AddCommonResponseHeader(apiContext)
_ = AddCommonResponseHeader(apiContext)
apiContext.Response.Header().Set("content-type", j.ContentType)
apiContext.Response.WriteHeader(code)
}

func (j *EncodingResponseWriter) Write(apiContext *types.APIContext, code int, obj interface{}) {
j.start(apiContext, code, obj)
j.Body(apiContext, apiContext.Response, obj)
_ = j.Body(apiContext, apiContext.Response, obj)
}

func (j *EncodingResponseWriter) Body(apiContext *types.APIContext, writer io.Writer, obj interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion clientbase/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (a *APIOperations) DoDelete(url string) error {
return err
}
defer func() {
io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()

Expand Down
3 changes: 1 addition & 2 deletions condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
err2 "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -312,7 +312,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
1 change: 0 additions & 1 deletion controller/cluster_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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
20 changes: 0 additions & 20 deletions controller/generic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package controller

import (
"context"
"strings"
"time"

errors2 "github.com/pkg/errors"
"github.com/rancher/lasso/pkg/controller"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -78,20 +75,3 @@ func isNamespace(namespace string, obj runtime.Object) bool {
}
return meta.GetNamespace() == namespace
}

func ignoreError(err error, checkString bool) bool {
err = errors2.Cause(err)
if errors.IsConflict(err) {
return true
}
if err == controller.ErrIgnore {
return true
}
if _, ok := err.(*ForgetError); ok {
return true
}
if checkString {
return strings.HasSuffix(err.Error(), "please apply your changes to the latest version and try again")
}
return false
}
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ func main() {
}

fmt.Println("Listening on 0.0.0.0:1234")
http.ListenAndServe("0.0.0.0:1234", server)
panic(http.ListenAndServe("0.0.0.0:1234", server))
}
2 changes: 1 addition & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func prepareDirs(dirs ...string) error {
}

func Gofmt(workDir, pkg string) error {
return filepath.Walk(filepath.Join(workDir, pkg), func(path string, info os.FileInfo, err error) error {
return filepath.Walk(filepath.Join(workDir, pkg), func(path string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}
Expand Down
11 changes: 6 additions & 5 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func Parse(rw http.ResponseWriter, req *http.Request, schemas *types.Schemas, ur
result.URLBuilder, err = urlbuilder.New(req, types.APIVersion{}, result.Schemas)
result.Type = "apiRoot"
result.Schema = result.Schemas.Schema(&builtin.Version, "apiRoot")
return result, nil
return result, err
}

result.URLBuilder, err = urlbuilder.New(req, *result.Version, result.Schemas)
Expand Down Expand Up @@ -169,9 +169,7 @@ func parseVersionAndSubContext(schemas *types.Schemas, escapedPath string) (*typ
}
version := &versions[0]

if strings.HasSuffix(escapedPath, "/") {
escapedPath = escapedPath[:len(escapedPath)-1]
}
escapedPath = strings.TrimSuffix(escapedPath, "/")

versionParts := strings.Split(version.Path, "/")
pp := strings.Split(escapedPath, "/")
Expand Down Expand Up @@ -295,7 +293,10 @@ func parseAction(url *url.URL) (string, string) {
}

func Body(req *http.Request) (map[string]interface{}, error) {
req.ParseMultipartForm(maxFormSize)
err := req.ParseMultipartForm(maxFormSize)
if err != nil {
return nil, err
}
if req.MultipartForm != nil {
return valuesToBody(req.MultipartForm.Value), nil
}
Expand Down
2 changes: 0 additions & 2 deletions parse/read_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
)

const reqMaxSize = (2 * 1 << 20) + 1

var bodyMethods = map[string]bool{
http.MethodPut: true,
http.MethodPost: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func GoroutineDumpOn(signals ...os.Signal) {
_, _ = io.WriteString(os.Stderr, p.BucketHeader(&bucket, true, len(buckets) > 1))
_, _ = io.WriteString(os.Stderr, p.StackLines(&bucket.Signature, srcLen, pkgLen, true))
}
io.Copy(os.Stderr, bytes.NewBuffer(buf))
_, _ = io.Copy(os.Stderr, bytes.NewBuffer(buf))
} else {
io.Copy(os.Stderr, src)
_, _ = io.Copy(os.Stderr, src)
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion pkg/subscribe/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func handler(apiContext *types.APIContext) error {
}

go func() {
readerGroup.Wait()
_ = readerGroup.Wait()
close(events)
}()

Expand Down
18 changes: 6 additions & 12 deletions scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ cd $(dirname $0)/..

echo Running validation

PACKAGES="$(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')"
if ! command -v golangci-lint; then
echo Skipping validation: no golangci-lint available
exit
fi

echo Running: go vet
go vet ${PACKAGES}
echo Running: golint
for i in ${PACKAGES}; do
if [ -n "$(golint $i | grep -v 'should have comment.*or be unexported' | tee /dev/stderr)" ]; then
failed=true
fi
done
test -z "$failed"
echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"
echo Running: golangci-lint
golangci-lint run
4 changes: 2 additions & 2 deletions store/proxy/proxy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *Store) getUser(apiContext *types.APIContext) string {
func (s *Store) doAuthed(apiContext *types.APIContext, request *rest.Request) rest.Result {
start := time.Now()
defer func() {
logrus.Tracef("GET: %v, %v", time.Now().Sub(start), s.resourcePlural)
logrus.Tracef("GET: %v, %v", time.Since(start), s.resourcePlural)
}()

for _, header := range authHeaders {
Expand Down Expand Up @@ -271,7 +271,7 @@ func (s *Store) retryList(namespace string, apiContext *types.APIContext, result
req := s.common(namespace, k8sClient.Get())
start := time.Now()
err = req.Do(apiContext.Request.Context()).Into(resultList)
logrus.Tracef("LIST: %v, %v", time.Now().Sub(start), s.resourcePlural)
logrus.Tracef("LIST: %v, %v", time.Since(start), s.resourcePlural)
if err != nil {
if i < 2 && strings.Contains(err.Error(), "Client.Timeout exceeded") {
logrus.Infof("Error on LIST %v: %v. Attempt: %v. Retrying", s.resourcePlural, err, i+1)
Expand Down
2 changes: 1 addition & 1 deletion types/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
commenter = regexp.MustCompile("(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)")
commenter = regexp.MustCompile(`(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)`)
)

func JSONEncoder(writer io.Writer, v interface{}) error {
Expand Down
3 changes: 3 additions & 0 deletions types/mapper/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (m Move) ModifySchema(s *types.Schema, schemas *types.Schemas) error {
if err != nil {
return err
}
if !ok {
return fmt.Errorf("failed to find field %s on schema %s", m.To, s.ID)
}
_, ok = toSchema.ResourceFields[toFieldName]
if ok && !strings.Contains(m.To, "/") && !m.DestDefined {
return fmt.Errorf("field %s already exists on schema %s", m.To, s.ID)
Expand Down