Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
removed etcd mandatory dependency (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
ortuman authored Jan 20, 2022
1 parent 8617cb5 commit 0c81f3d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
3 changes: 0 additions & 3 deletions pkg/c2s/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"strings"
"sync"
"time"

kitlog "github.com/go-kit/log"

Expand All @@ -38,8 +37,6 @@ const (
resourceKeyPrefix = "r://"
)

const clearActiveKeyTimeout = time.Minute

// ResourceManager type is in charge of keeping track of all cluster resources.
type ResourceManager struct {
kv kv.KV
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "time"

// Config contains etcd configuration parameters.
type Config struct {
Endpoints []string `fig:"endpoints" default:"[http://localhost:2379]"`
Endpoints []string `fig:"endpoints"`
DialTimeout time.Duration `fig:"dial_timeout" default:"20s"`
DialKeepAliveTime time.Duration `fig:"dial_keep_alive_time" default:"30s"`
DialKeepAliveTimeout time.Duration `fig:"dial_keep_alive_timeout" default:"10s"`
Expand Down
41 changes: 41 additions & 0 deletions pkg/cluster/kv/nop_kv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2021 The jackal Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package kv

import "context"

// NewNopKV returns a KV that doesn't do anything.
func NewNopKV() KV { return &nopKV{} }

type nopKV struct{}

func (k *nopKV) Put(_ context.Context, _ string, _ string) error { return nil }
func (k *nopKV) Get(_ context.Context, _ string) ([]byte, error) { return nil, nil }

func (k *nopKV) GetPrefix(_ context.Context, _ string) (map[string][]byte, error) {
return nil, nil
}

func (k *nopKV) Del(_ context.Context, _ string) error { return nil }

func (k *nopKV) Watch(_ context.Context, _ string, _ bool) <-chan WatchResp {
// return an already closed channel
retCh := make(chan WatchResp)
close(retCh)
return retCh
}

func (k *nopKV) Start(_ context.Context) error { return nil }
func (k *nopKV) Stop(_ context.Context) error { return nil }
2 changes: 1 addition & 1 deletion pkg/cluster/locker/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ type Locker interface {

// Lock defines distributed lock object.
type Lock interface {
// Releases releases a previously acquired lock.
// Release releases a previously acquired lock.
Release(ctx context.Context) error
}
33 changes: 33 additions & 0 deletions pkg/cluster/locker/nop_locker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2021 The jackal Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package locker

import "context"

// NewNopLocker returns a Locker that doesn't do anything.
func NewNopLocker() Locker { return &nopLocker{} }

type nopLocker struct{}

func (l *nopLocker) AcquireLock(_ context.Context, _ string) (Lock, error) {
return &nopLock{}, nil
}

func (l *nopLocker) Start(_ context.Context) error { return nil }
func (l *nopLocker) Stop(_ context.Context) error { return nil }

type nopLock struct{}

func (l *nopLock) Release(_ context.Context) error { return nil }
12 changes: 8 additions & 4 deletions pkg/jackal/jackal.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func New(output io.Writer, args []string) *Jackal {
output: output,
args: args,
waitStopCh: make(chan os.Signal, 1),
locker: locker.NewNopLocker(),
kv: kv.NewNopKV(),
}
}

Expand Down Expand Up @@ -212,11 +214,13 @@ func (j *Jackal) Run() error {
j.hk = hook.NewHooks()

// init etcd
if err := j.checkEtcdHealth(cfg.Cluster.Etcd.Endpoints); err != nil {
return err
if len(cfg.Cluster.Etcd.Endpoints) > 0 {
if err := j.checkEtcdHealth(cfg.Cluster.Etcd.Endpoints); err != nil {
return err
}
j.initLocker(cfg.Cluster.Etcd)
j.initKVStore(cfg.Cluster.Etcd)
}
j.initLocker(cfg.Cluster.Etcd)
j.initKVStore(cfg.Cluster.Etcd)

// init cluster connection manager
j.initClusterConnManager()
Expand Down

0 comments on commit 0c81f3d

Please sign in to comment.