mirror of https://github.com/k3s-io/k3s
Merge pull request #24646 from nikhiljindal/removeMasterDep
Automatic merge from submit-queue Move SSHTunneler to genericapiserver and remove federated-apiserver's dependency on pkg/master cc @jianhuizpull/6/head
commit
b04f6ffc48
|
@ -101,11 +101,11 @@ func Run(s *options.APIServer) error {
|
|||
}
|
||||
|
||||
// Setup tunneler if needed
|
||||
var tunneler master.Tunneler
|
||||
var tunneler genericapiserver.Tunneler
|
||||
var proxyDialerFn apiserver.ProxyDialerFunc
|
||||
if len(s.SSHUser) > 0 {
|
||||
// Get ssh key distribution func, if supported
|
||||
var installSSH master.InstallSSHKey
|
||||
var installSSH genericapiserver.InstallSSHKey
|
||||
if cloud != nil {
|
||||
if instances, supported := cloud.Instances(); supported {
|
||||
installSSH = instances.AddSSHKeyToAllInstances
|
||||
|
@ -122,7 +122,7 @@ func Run(s *options.APIServer) error {
|
|||
Host: net.JoinHostPort("127.0.0.1", strconv.FormatUint(uint64(s.KubeletConfig.Port), 10)),
|
||||
Path: "healthz",
|
||||
}
|
||||
tunneler = master.NewSSHTunneler(s.SSHUser, s.SSHKeyfile, healthCheckPath, installSSH)
|
||||
tunneler = genericapiserver.NewSSHTunneler(s.SSHUser, s.SSHKeyfile, healthCheckPath, installSSH)
|
||||
|
||||
// Use the tunneler's dialer to connect to the kubelet
|
||||
s.KubeletConfig.Dial = tunneler.Dial
|
||||
|
|
|
@ -42,7 +42,6 @@ import (
|
|||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver"
|
||||
"k8s.io/kubernetes/pkg/master"
|
||||
"k8s.io/kubernetes/pkg/registry/cachesize"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||
|
@ -120,7 +119,7 @@ func Run(s *options.APIServer) error {
|
|||
var proxyDialerFn apiserver.ProxyDialerFunc
|
||||
if len(s.SSHUser) > 0 {
|
||||
// Get ssh key distribution func, if supported
|
||||
var installSSH master.InstallSSHKey
|
||||
var installSSH genericapiserver.InstallSSHKey
|
||||
if cloud != nil {
|
||||
if instances, supported := cloud.Instances(); supported {
|
||||
installSSH = instances.AddSSHKeyToAllInstances
|
||||
|
@ -137,7 +136,7 @@ func Run(s *options.APIServer) error {
|
|||
Host: net.JoinHostPort("127.0.0.1", strconv.FormatUint(uint64(s.KubeletConfig.Port), 10)),
|
||||
Path: "healthz",
|
||||
}
|
||||
tunneler := master.NewSSHTunneler(s.SSHUser, s.SSHKeyfile, healthCheckPath, installSSH)
|
||||
tunneler := genericapiserver.NewSSHTunneler(s.SSHUser, s.SSHKeyfile, healthCheckPath, installSSH)
|
||||
|
||||
// Use the tunneler's dialer to connect to the kubelet
|
||||
s.KubeletConfig.Dial = tunneler.Dial
|
||||
|
@ -318,6 +317,6 @@ func getRuntimeConfigValue(s *options.APIServer, apiKey string, defaultValue boo
|
|||
// Parses the given runtime-config and formats it into genericapiserver.APIResourceConfigSource
|
||||
func parseRuntimeConfig(s *options.APIServer) (genericapiserver.APIResourceConfigSource, error) {
|
||||
// TODO: parse the relevant group version when we add any.
|
||||
resourceConfig := master.DefaultAPIResourceConfigSource()
|
||||
resourceConfig := genericapiserver.NewResourceConfig()
|
||||
return resourceConfig, nil
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package master
|
||||
package genericapiserver
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package master
|
||||
package genericapiserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -66,27 +66,6 @@ func TestSecondsSinceSync(t *testing.T) {
|
|||
assert.Equal(int64(-2678400), tunneler.SecondsSinceSync())
|
||||
}
|
||||
|
||||
// TestIsTunnelSyncHealthy verifies that the 600 second lag test
|
||||
// is honored.
|
||||
func TestIsTunnelSyncHealthy(t *testing.T) {
|
||||
tunneler := &SSHTunneler{}
|
||||
master, etcdserver, _, assert := setUp(t)
|
||||
defer etcdserver.Terminate(t)
|
||||
master.tunneler = tunneler
|
||||
|
||||
// Pass case: 540 second lag
|
||||
tunneler.lastSync = time.Date(2015, time.January, 1, 1, 1, 1, 1, time.UTC).Unix()
|
||||
tunneler.lastSSHKeySync = time.Date(2015, time.January, 1, 1, 1, 1, 1, time.UTC).Unix()
|
||||
tunneler.clock = util.NewFakeClock(time.Date(2015, time.January, 1, 1, 9, 1, 1, time.UTC))
|
||||
err := master.IsTunnelSyncHealthy(nil)
|
||||
assert.NoError(err, "IsTunnelSyncHealthy() should not have returned an error.")
|
||||
|
||||
// Fail case: 720 second lag
|
||||
tunneler.clock = util.NewFakeClock(time.Date(2015, time.January, 1, 1, 12, 1, 1, time.UTC))
|
||||
err = master.IsTunnelSyncHealthy(nil)
|
||||
assert.Error(err, "IsTunnelSyncHealthy() should have returned an error.")
|
||||
}
|
||||
|
||||
// generateTempFile creates a temporary file path
|
||||
func generateTempFilePath(prefix string) string {
|
||||
tmpPath, _ := filepath.Abs(fmt.Sprintf("%s/%s-%d", os.TempDir(), prefix, time.Now().Unix()))
|
|
@ -102,7 +102,7 @@ type Config struct {
|
|||
EventTTL time.Duration
|
||||
KubeletClient kubeletclient.KubeletClient
|
||||
// Used to start and monitor tunneling
|
||||
Tunneler Tunneler
|
||||
Tunneler genericapiserver.Tunneler
|
||||
|
||||
disableThirdPartyControllerForTesting bool
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ type Master struct {
|
|||
disableThirdPartyControllerForTesting bool
|
||||
|
||||
// Used to start and monitor tunneling
|
||||
tunneler Tunneler
|
||||
tunneler genericapiserver.Tunneler
|
||||
}
|
||||
|
||||
// thirdPartyEntry combines objects storage and API group into one struct
|
||||
|
|
|
@ -1010,6 +1010,38 @@ func TestThirdPartyDiscovery(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type FakeTunneler struct {
|
||||
SecondsSinceSyncValue int64
|
||||
SecondsSinceSSHKeySyncValue int64
|
||||
}
|
||||
|
||||
func (t *FakeTunneler) Run(genericapiserver.AddressFunc) {}
|
||||
func (t *FakeTunneler) Stop() {}
|
||||
func (t *FakeTunneler) Dial(net, addr string) (net.Conn, error) { return nil, nil }
|
||||
func (t *FakeTunneler) SecondsSinceSync() int64 { return t.SecondsSinceSyncValue }
|
||||
func (t *FakeTunneler) SecondsSinceSSHKeySync() int64 { return t.SecondsSinceSSHKeySyncValue }
|
||||
|
||||
// TestIsTunnelSyncHealthy verifies that the 600 second lag test
|
||||
// is honored.
|
||||
func TestIsTunnelSyncHealthy(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
tunneler := &FakeTunneler{}
|
||||
master := &Master{
|
||||
GenericAPIServer: &genericapiserver.GenericAPIServer{},
|
||||
tunneler: tunneler,
|
||||
}
|
||||
|
||||
// Pass case: 540 second lag
|
||||
tunneler.SecondsSinceSyncValue = 540
|
||||
err := master.IsTunnelSyncHealthy(nil)
|
||||
assert.NoError(err, "IsTunnelSyncHealthy() should not have returned an error.")
|
||||
|
||||
// Fail case: 720 second lag
|
||||
tunneler.SecondsSinceSyncValue = 720
|
||||
err = master.IsTunnelSyncHealthy(nil)
|
||||
assert.Error(err, "IsTunnelSyncHealthy() should have returned an error.")
|
||||
}
|
||||
|
||||
func testThirdPartyDiscovery(t *testing.T, version string) {
|
||||
_, etcdserver, server, assert := initThirdParty(t, version)
|
||||
// TODO: Uncomment when fix #19254
|
||||
|
|
Loading…
Reference in New Issue