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

fix: update dependencies #72

Merged
merged 2 commits into from
Jan 10, 2024
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
5 changes: 0 additions & 5 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ninech/apis"
"github.com/ninech/nctl/api/log"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -56,12 +55,8 @@ func New(ctx context.Context, apiClusterContext, project string, opts ...ClientO
return nil, err
}

mapper := apis.StaticRESTMapper(scheme)
ctrox marked this conversation as resolved.
Show resolved Hide resolved
mapper.Add(corev1.SchemeGroupVersion.WithKind("Secret"), meta.RESTScopeNamespace)

c, err := runtimeclient.NewWithWatch(client.Config, runtimeclient.Options{
Scheme: scheme,
Mapper: mapper,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion api/log/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestClient(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%s %s\n", expectedTime.Local().Format(time.RFC3339), expectedLine), buf.String())
buf.Reset()

if err := c.TailQuery(ctx, 0, out, Query{Limit: 10}); err != nil {
if err := c.TailQuery(ctx, 0, out, Query{QueryString: "{app=\"test\"}", Limit: 10}); err != nil {
t.Fatal(err)
}
assert.Equal(t, fmt.Sprintf("%s %s\n", expectedTime.Local().Format(time.RFC3339), expectedLine), buf.String())
Expand Down
31 changes: 26 additions & 5 deletions api/log/fake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package log

import (
"errors"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -9,10 +10,12 @@ import (
"time"

"github.com/gorilla/websocket"
"github.com/grafana/loki/pkg/logcli/volume"
"github.com/grafana/loki/pkg/loghttp"
legacy "github.com/grafana/loki/pkg/loghttp/legacy"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/httpreq"
"github.com/grafana/loki/pkg/util/marshal"
)

Expand All @@ -32,6 +35,11 @@ func NewFake(t *testing.T, expectedTime time.Time, expectedLines ...string) *fak
func lokiTailHandler(t *testing.T, timestamp time.Time, lines []string) http.HandlerFunc {
upgrader := websocket.Upgrader{}
return func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
t.Error(err)
return
}

req, err := loghttp.ParseTailQuery(r)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -64,7 +72,8 @@ func lokiTailHandler(t *testing.T, timestamp time.Time, lines []string) http.Han
},
}

if err := marshal.WriteTailResponseJSON(resp, c); err != nil {
connWriter := marshal.NewWebsocketJSONWriter(c)
if err := marshal.WriteTailResponseJSON(resp, connWriter, httpreq.ExtractEncodingFlags(r)); err != nil {
t.Error(err)
return
}
Expand Down Expand Up @@ -125,21 +134,33 @@ func (f fake) LiveTailQueryConn(queryStr string, delayFor time.Duration, limit i
}

func (f fake) ListLabelNames(quiet bool, start, end time.Time) (*loghttp.LabelResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) ListLabelValues(name string, quiet bool, start, end time.Time) (*loghttp.LabelResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) Series(matchers []string, start, end time.Time, quiet bool) (*loghttp.SeriesResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) Query(queryStr string, limit int, time time.Time, direction logproto.Direction, quiet bool) (*loghttp.QueryResponse, error) {
return nil, nil
return nil, errors.New("not implemented")
}

func (f fake) GetOrgID() string {
return "fake"
}

func (f fake) GetStats(queryStr string, start, end time.Time, quiet bool) (*logproto.IndexStatsResponse, error) {
return nil, errors.New("not implemented")
}

func (f fake) GetVolume(query *volume.Query) (*loghttp.QueryResponse, error) {
return nil, errors.New("not implemented")
}

func (f fake) GetVolumeRange(query *volume.Query) (*loghttp.QueryResponse, error) {
return nil, errors.New("not implemented")
}
4 changes: 2 additions & 2 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -208,7 +208,7 @@ func (app *applicationCmd) config() apps.Config {
Command: app.DeployJob.Command,
},
FiniteJob: apps.FiniteJob{
Retries: pointer.Int32(app.DeployJob.Retries),
Retries: ptr.To(app.DeployJob.Retries),
Timeout: &metav1.Duration{Duration: app.DeployJob.Timeout},
},
}
Expand Down
60 changes: 30 additions & 30 deletions create/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -120,11 +120,11 @@ func TestApplication(t *testing.T) {
},
Wait: false,
Name: "custom-name",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
Hosts: []string{"custom.example.org", "custom2.example.org"},
Port: pointer.Int32(1337),
Replicas: pointer.Int32(42),
BasicAuth: pointer.Bool(false),
Port: ptr.To(int32(1337)),
Replicas: ptr.To(int32(42)),
BasicAuth: ptr.To(false),
Env: map[string]string{"hello": "world"},
BuildEnv: map[string]string{"BP_GO_TARGETS": "./cmd/web-server"},
DeployJob: deployJob{Command: "date", Name: "print-date", Retries: 2, Timeout: time.Minute},
Expand Down Expand Up @@ -152,8 +152,8 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Wait: false,
Name: "basic-auth",
Size: pointer.String("mini"),
BasicAuth: pointer.Bool(true),
Size: ptr.To("mini"),
BasicAuth: ptr.To(true),
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
assert.Equal(t, cmd.Name, app.Name)
Expand All @@ -165,8 +165,8 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
Username: pointer.String("deploy"),
Password: pointer.String("hunter2"),
Username: ptr.To("deploy"),
Password: ptr.To("hunter2"),
},
Wait: false,
Name: "user-pass-auth",
Expand All @@ -187,11 +187,11 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKey: pointer.String(dummySSHRSAPrivateKey),
SSHPrivateKey: ptr.To(dummySSHRSAPrivateKey),
},
Wait: false,
Name: "ssh-key-auth",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
auth := util.GitAuth{SSHPrivateKey: cmd.Git.SSHPrivateKey}
Expand All @@ -208,11 +208,11 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKey: pointer.String(dummySSHED25519PrivateKey),
SSHPrivateKey: ptr.To(dummySSHED25519PrivateKey),
},
Wait: false,
Name: "ssh-key-auth-ed25519",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
auth := util.GitAuth{SSHPrivateKey: cmd.Git.SSHPrivateKey}
Expand All @@ -229,14 +229,14 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKeyFromFile: pointer.String(filenameRSAKey),
SSHPrivateKeyFromFile: ptr.To(filenameRSAKey),
},
Wait: false,
Name: "ssh-key-auth-from-file",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
auth := util.GitAuth{SSHPrivateKey: pointer.String("notused")}
auth := util.GitAuth{SSHPrivateKey: ptr.To("notused")}
authSecret := auth.Secret(app)
if err := apiClient.Get(ctx, api.ObjectName(authSecret), authSecret); err != nil {
t.Fatal(err)
Expand All @@ -250,14 +250,14 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKeyFromFile: pointer.String(filenameED25519Key),
SSHPrivateKeyFromFile: ptr.To(filenameED25519Key),
},
Wait: false,
Name: "ssh-key-auth-from-file-ed25519",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
auth := util.GitAuth{SSHPrivateKey: pointer.String("notused")}
auth := util.GitAuth{SSHPrivateKey: ptr.To("notused")}
authSecret := auth.Secret(app)
if err := apiClient.Get(ctx, api.ObjectName(authSecret), authSecret); err != nil {
t.Fatal(err)
Expand All @@ -271,11 +271,11 @@ func TestApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKey: pointer.String("not valid"),
SSHPrivateKey: ptr.To("not valid"),
},
Wait: false,
Name: "ssh-key-auth-non-valid",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
},
errorExpected: true,
},
Expand All @@ -286,7 +286,7 @@ func TestApplication(t *testing.T) {
},
Wait: false,
Name: "deploy-job-empty-command",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
DeployJob: deployJob{Command: "", Name: "print-date", Retries: 2, Timeout: time.Minute},
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand All @@ -300,7 +300,7 @@ func TestApplication(t *testing.T) {
},
Wait: false,
Name: "deploy-job-empty-name",
Size: pointer.String("mini"),
Size: ptr.To("mini"),
DeployJob: deployJob{Command: "date", Name: "", Retries: 2, Timeout: time.Minute},
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestApplicationWait(t *testing.T) {
Wait: true,
WaitTimeout: time.Second * 5,
Name: "some-name",
BasicAuth: pointer.Bool(true),
BasicAuth: ptr.To(true),
}
project := "default"

Expand Down Expand Up @@ -411,7 +411,7 @@ func TestApplicationWait(t *testing.T) {
app.Status.AtProvider.Hosts = []apps.VerificationStatus{{Name: "host.example.org"}}
app.Status.AtProvider.CNAMETarget = "some.target.example.org"
app.Status.AtProvider.BasicAuthSecret = &meta.LocalReference{Name: basicAuth.Name}
if err := apiClient.Status().Update(ctx, app); err != nil {
ctrox marked this conversation as resolved.
Show resolved Hide resolved
if err := apiClient.Update(ctx, app); err != nil {
errors <- err
}

Expand All @@ -428,12 +428,12 @@ func TestApplicationWait(t *testing.T) {
}

build.Status.AtProvider.BuildStatus = buildStatusRunning
if err := apiClient.Status().Update(ctx, build); err != nil {
if err := apiClient.Update(ctx, build); err != nil {
errors <- err
}

build.Status.AtProvider.BuildStatus = buildStatusSuccess
if err := apiClient.Status().Update(ctx, build); err != nil {
if err := apiClient.Update(ctx, build); err != nil {
errors <- err
}

Expand All @@ -442,7 +442,7 @@ func TestApplicationWait(t *testing.T) {
}

release.Status.AtProvider.ReleaseStatus = releaseStatusAvailable
if err := apiClient.Status().Update(ctx, release); err != nil {
if err := apiClient.Update(ctx, release); err != nil {
errors <- err
}
}
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestApplicationBuildFail(t *testing.T) {
}

build.Status.AtProvider.BuildStatus = buildStatusError
if err := client.Status().Update(ctx, build); err != nil {
if err := client.Update(ctx, build); err != nil {
errors <- err
}
}
Expand Down Expand Up @@ -553,5 +553,5 @@ func setResourceCondition(ctx context.Context, apiClient *api.Client, mg resourc
}

mg.SetConditions(condition)
return apiClient.Status().Update(ctx, mg)
return apiClient.Update(ctx, mg)
}
2 changes: 1 addition & 1 deletion create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestCreate(t *testing.T) {
}

asa.SetConditions(runtimev1.Available())
if err := apiClient.Status().Update(ctx, asa); err != nil {
if err := apiClient.Update(ctx, asa); err != nil {
errChan <- err
}
}
Expand Down
4 changes: 2 additions & 2 deletions create/project_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/api/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

// all fields need to be pointers so we can detect if they have been set by
Expand Down Expand Up @@ -41,7 +41,7 @@ func (cmd *configCmd) newProjectConfig(namespace string) *apps.ProjectConfig {
Command: cmd.DeployJob.Command,
},
FiniteJob: apps.FiniteJob{
Retries: pointer.Int32(cmd.DeployJob.Retries),
Retries: ptr.To(cmd.DeployJob.Retries),
Timeout: &metav1.Duration{Duration: cmd.DeployJob.Timeout},
},
}
Expand Down
10 changes: 5 additions & 5 deletions create/project_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/ninech/nctl/api/util"
"github.com/ninech/nctl/internal/test"
"github.com/stretchr/testify/assert"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestProjectConfig(t *testing.T) {
Expand All @@ -29,10 +29,10 @@ func TestProjectConfig(t *testing.T) {
"all fields set": {
cmd: configCmd{
Size: string(test.AppMini),
Port: pointer.Int32(1337),
Replicas: pointer.Int32(42),
Port: ptr.To(int32(1337)),
Replicas: ptr.To(int32(42)),
Env: &map[string]string{"key1": "val1"},
BasicAuth: pointer.Bool(true),
BasicAuth: ptr.To(true),
DeployJob: deployJob{
Command: "exit 0", Name: "exit",
Retries: 1, Timeout: time.Minute * 5,
Expand All @@ -55,7 +55,7 @@ func TestProjectConfig(t *testing.T) {
"some fields not set": {
cmd: configCmd{
Size: string(test.AppMicro),
Replicas: pointer.Int32(1),
Replicas: ptr.To(int32(1)),
},
project: "namespace-2",
checkConfig: func(t *testing.T, cmd configCmd, cfg *apps.ProjectConfig) {
Expand Down
Loading