gcloud functions deploy go runtime error "undefined: unsafe.Slice; Error ID: 2f5e35a0" - go

While deploying to google cloud function, I am getting this error:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: # projectname/vendor/golang.org/x/sys/unix
src/projectname/vendor/golang.org/x/sys/unix/syscall.go:83:16: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
src/projectname/vendor/golang.org/x/sys/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice; Error ID: 2f5e35a0
Here's my command:
gcloud functions deploy servicename --region=us-central1 --entry-point=gofunctionname --runtime=go116 --source=.
I am using vendoring to package my dependencies. It's been a while I have updated this function. And first time I noticed this error.
Any help would be much appreciated.

As DazWilkin suggested above, unsafe.Slice was added as part of Go 1.17 and GCP Functions support Go 1.16 as of now.
I had to revert back the golang.org/x/sys module in the go.mod file and it worked for me.
From
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
To
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
With this change, I am able to build and deploy the code to Google Cloud Functions.

As of the time of writing this, Google Cloud Functions now supports Go 1.18 and Go 1.19.
Update your project to go119 and you shouldn't have this issue anymore. For example:
gcloud functions deploy servicename --runtime=go119 --region=us-central1

Related

Error go test -v on https://github.com/slicen/cert-manager-webhook-linode

I completely make a config and create a token on linode
but i got this error when try to test my fetch-test-binaries.sh
this is the message
go test -v
# github.com/slicen/cert-manager-webhook-linode [github.com/slicen/cert-manager-webhook-linode.test]
./main_test.go:20:7: undefined: dns.SetBinariesPath
./main_test.go:20:23: undefined: kubeBuilderBinPath
FAIL github.com/slicen/cert-manager-webhook-linode [build failed]
make: *** [Makefile:15: verify] Error 2
can someone help me to resolve please ?
The error on file
main_test.go line 7 & 23 Link FIle : https://github.com/slicen/cert-manager-webhook-linode/blob/master/main_test.go
and makefile line 15 Link File : https://github.com/slicen/cert-manager-webhook-linode/blob/master/Makefile
The Repository Link : https://github.com/slicen/cert-manager-webhook-linode
I have tried to resolve with downgrade or upgrade my Go Version and searching but i found nothing,
I tried to just go test -v(not doing anything, just clone & go test) but i got same error
Please Help me, Thanks
SetBinariesPath was removed from cert-manager in commit cd92bf321fe14f857f34763583071e068f6c96b3
github.com/slicen/cert-manager-webhook-linode was updated to a newer version of cert-manager in commit 7131f7755b1278e48341f0d71fabac5b56b964fb - and it looks like that moved to a version of cert-manager which includes the removal of SetBinariesPath. The var declaration for kubeBuilderBinPath was correctly stripped away, but the call to dns.SetBinariesPath and a reference to the now removed kubeBuilderBinPath still remain.
So, essentially the code in main_test.go is invalid - at minimum line 20 should be removed.

golang build at /vendor/github.com/weaveworks/promrus is giving an error: undefined: logrus.Level

I am trying to build the golang package (/vendor/github.com/weaveworks/promrus) in IBM Z (Mainframe). And I am getting an error: ./promrus.go:15:25: undefined: logrus.Level
My go version is: go version go1.16.2 zos/s390x
I have tried to read through the article: https://www.ibm.com/docs/en/sdk-go-zos/1.16?topic=porting-applications-zos
and have added a build constraint (//+build zos) as given below. But still the undefined error is not going away. Is there any way to build? Pls help and thanks in advance.
//+build zos
package promrus
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus" )
// PrometheusHook exposes Prometheus counters for each of logrus' log
levels. type PrometheusHook struct {
counterVec *prometheus.CounterVec }
User opened up an official support Case with IBM and found resolution.

Unable to invoke aws lambda locally using sls

Im using sls framework to launch my code and it was working fine until today.
serverless.yml's configuration wasnt modified and ive tried reinstalling sls but nothing seems to work.
The following message occurs for all my repos after throwing the following command:
sls invoke local -f function_name --accountId $accountId
Error message:
TypeError: Cannot read property 'Fn::ImportValue' of undefined
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:188:22
at Array.map (<anonymous>)
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:187:53
at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.attempt.Promise.try (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/method.js:39:29)
at AwsInvokeLocal.loadEnvVars (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:154:25)
at AwsInvokeLocal.tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:456:21)
at process.topLevelDomainCallback (domain.js:137:15)```
Fixed by specifying the stage
I encountered the same issue and resolved it by specifying the stage with -s <STAGE> when executing sls invoke local.
Why this worked for me
I'm using serverless-dotenv-plugin, which lets me split my .env files by stage like so:
.env.dev
.env.test
.env.prod
Adding the stage helps specify which .env file to use with your local invocation. Without it, Serverless was trying to import .env with no stage appended, which doesn't exist on my project.
I was experiencing the same issue as well. It turns out that the latest version of Serverless seems to have bug. Downgrading to a previous version of sls fixed mine. I downgraded to verion 1.80, and it works fine now.
I figured out what's wrong. There was a warning while the invocation was running:
Serverless Warning --------------------------------------
A valid environment variable to satisfy the declaration 'env:MY_API_KEY' could not be found.
Since it was a warning I just ignored it and it previously worked but apparently the framework doesnt like it now. Dealing with the warning either by removing the variable or defining it resolved my issue.
For me all the environment variables had to be initialized for resolving error.
Serverless Warning --------------------------------------
A valid environment variable to satisfy the declaration 'env:<variable>' could not be found.
So I did this -
export <variable>=""
I got stuck with this issue as well. The reason is the environment variables defined in serverless.yml was not in the local .env file.
name: ...
handler: ...
environment:
API_KEY: ${env:API_KEY}
STAGE: ${self:provider.stage}
Here, API_KEY and STAGE should exist in .env.

Golang failes to change the name of imported module

I'm trying to bring SkyDNSv1 back to life and build it from my fork (here is Dockerfile). SkyDNS was really good and simple tool for the quick service discovery, but it wasn't updated for a long time.
There is an error in build process and it's caused by third party library. I cannot figure out why does it happen:
$ docker build --no-cache -t skydns1 .
Sending build context to Docker daemon 1.566 MB
Sending build context to Docker daemon
Step 0 : FROM golang:1.4.2
---> 3e8cb8e0c765
Step 1 : WORKDIR /go/src
---> Running in 3a06cf460ad9
---> 1dd14a099164
Removing intermediate container 3a06cf460ad9
Step 2 : RUN go get github.com/codegangsta/cli
---> Running in eabcfd6fe621
---> c9ea222f2d74
Removing intermediate container eabcfd6fe621
Step 3 : RUN go get github.com/vitalyisaev2/skydns1
---> Running in 3264582b2e7a
# github.com/rcrowley/go-metrics/influxdb
github.com/rcrowley/go-metrics/influxdb/influxdb.go:19: undefined: client.ClientConfig
github.com/rcrowley/go-metrics/influxdb/influxdb.go:38: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:44: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:52: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:60: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:70: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:82: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:93: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:106: client.WriteSeries undefined (type *client.Client has no field or method WriteSeries)
INFO[0075] The command [/bin/sh -c go get github.com/vitalyisaev2/skydns1] returned a non-zero code:
But if you look through the file causing this error, you'll notice that Golang is confused about influxdb/client. I think that compiler doesn't replace imported name client with influxClient as it should do:
package influxdb
import (
"fmt"
influxClient "github.com/influxdb/influxdb/client"
"github.com/rcrowley/go-metrics"
"log"
"time"
)
Probably I just missing an obvious mistake. Any help will be appreciated.
The Go compiler doesn't replace or rewrite anything, the code is just wrong. The github.com/rcrowley/go-metrics/influxdb package was written with some other influxdb client code that no longer exists. (Looks like there are a couple github issues open about this already)
If you look at the current influxdb/client package, you'll see there's no Series, ClientConfig, or Client.WriteSeries at all. You'll need to drop the dependency on github.com/rcrowley/go-metrics/influxdb in order to get your project to build.

Can't build go project in travis

I started to create a very light weight message broker to practice go, travis and some aws services all in one project.
My current problem is that I can build, run and test my develop branch on my local machine however when travis attempts to build it I get a compile error. The code it doesn't like came straight from AWS examples to further deepen the mystery for me.
Travis failed build
https://travis-ci.org/hevnly/eevy/builds/65687886
Github repo https://github.com/hevnly/eevy/tree/92412cf729ed546d698ded1e514d2d54c340ff81
Error
handler/lambda.go:31: cannot use "github.com/awslabs/aws-sdk-go/aws".Config literal (type *"github.com/awslabs/aws-sdk-go/aws".Config) as type *"github.com/aws/aws-sdk-go/aws".Config in argument to lambda.New
handler/sqs.go:26: cannot use "github.com/awslabs/aws-sdk-go/aws".Config literal (type *"github.com/awslabs/aws-sdk-go/aws".Config) as type *"github.com/aws/aws-sdk-go/aws".Config in argument to sqs.New
Sample of code
svc := lambda.New(&aws.Config{Region: "eu-west-1"})
Ok, I have just tried to go get your repo and got the same error:
handler/lambda.go:29: cannot use "github.com/awslabs/aws-sdk-go/aws".Config literal (type *"github.com/awslabs/aws-sdk-go/aws".Config) as type *"github.com/aws/aws-sdk-go/aws".Config in argument to lambda.New
handler/sqs.go:26: cannot use "github.com/awslabs/aws-sdk-go/aws".Config literal (type *"github.com/awslabs/aws-sdk-go/aws".Config) as type *"github.com/aws/aws-sdk-go/aws".Config in argument to sqs.New
I advice you to start using a dependency manager, so you will fix your dependencies inside your repo and have reproducible builds in any place.
My recommendation is Godep, but there are others out there.

Resources