2017-09-14 09:40:34 -07:00
|
|
|
/*
|
|
|
|
|
Copyright 2017 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
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 agent to manage Kubernetes storage attach events.
|
|
|
|
|
package agent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
"github.com/coreos/pkg/capnslog"
|
|
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2017-12-04 08:33:19 -08:00
|
|
|
"github.com/rook/rook/pkg/daemon/agent/cluster"
|
|
|
|
|
"github.com/rook/rook/pkg/daemon/agent/flexvolume"
|
|
|
|
|
"github.com/rook/rook/pkg/daemon/agent/flexvolume/attachment"
|
|
|
|
|
"github.com/rook/rook/pkg/daemon/agent/flexvolume/manager/ceph"
|
2017-10-25 12:23:15 -07:00
|
|
|
"k8s.io/api/core/v1"
|
2017-09-14 09:40:34 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "rook-agent")
|
|
|
|
|
|
|
|
|
|
// Agent represent all the references needed to manage a Rook agent
|
|
|
|
|
type Agent struct {
|
|
|
|
|
context *clusterd.Context
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New creates an Agent instance
|
|
|
|
|
func New(context *clusterd.Context) *Agent {
|
2017-10-25 12:23:15 -07:00
|
|
|
return &Agent{context: context}
|
2017-09-14 09:40:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run the agent
|
|
|
|
|
func (a *Agent) Run() error {
|
|
|
|
|
|
2017-12-04 09:03:06 -08:00
|
|
|
volumeAttachmentController, err := attachment.New(a.context)
|
2017-09-14 09:40:34 -07:00
|
|
|
if err != nil {
|
2017-10-25 12:23:15 -07:00
|
|
|
return fmt.Errorf("failed to create volume attachment controller: %+v", err)
|
2017-09-14 09:40:34 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-25 12:23:15 -07:00
|
|
|
volumeManager := ceph.NewVolumeManager(a.context)
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
flexvolumeController := flexvolume.NewController(a.context, volumeAttachmentController, volumeManager)
|
2017-10-25 12:23:15 -07:00
|
|
|
|
|
|
|
|
flexvolumeServer := flexvolume.NewFlexvolumeServer(
|
|
|
|
|
a.context,
|
|
|
|
|
flexvolumeController,
|
|
|
|
|
volumeManager,
|
|
|
|
|
)
|
|
|
|
|
|
2017-09-14 09:40:34 -07:00
|
|
|
flexvolumeServer.Start()
|
|
|
|
|
|
2017-10-25 12:23:15 -07:00
|
|
|
// create a cluster controller and tell it to start watching for changes to clusters
|
|
|
|
|
clusterController := cluster.NewClusterController(
|
|
|
|
|
a.context,
|
|
|
|
|
flexvolumeController,
|
|
|
|
|
volumeAttachmentController,
|
|
|
|
|
volumeManager)
|
|
|
|
|
stopChan := make(chan struct{})
|
|
|
|
|
clusterController.StartWatch(v1.NamespaceAll, stopChan)
|
|
|
|
|
|
2017-09-14 09:40:34 -07:00
|
|
|
sigc := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(sigc, syscall.SIGTERM)
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-sigc:
|
|
|
|
|
logger.Infof("shutdown signal received, exiting...")
|
|
|
|
|
flexvolumeServer.Stop()
|
2017-10-25 12:23:15 -07:00
|
|
|
close(stopChan)
|
2017-09-14 09:40:34 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|