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

Feat: Disk discovery #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ COPY go.sum go.sum
# RUN go mod download

# Copy the go source
COPY main.go main.go
COPY cmd/ cmd/
COPY api/ api/
COPY pkg/ pkg/
COPY vendor/ vendor/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -mod vendor -o curve-operator main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -mod vendor -o curve-operator cmd/main.go

##
# Use debian-9 as base image to package the curve-operator binary
Expand All @@ -41,7 +41,7 @@ RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted" > /etc/ap

# Install utility tools
RUN apt-get update -y && \
apt-get install -y coreutils dnsutils iputils-ping iproute2 telnet curl vim less wget graphviz unzip tcpdump gdb && \
apt-get install -y coreutils dnsutils iputils-ping iproute2 telnet curl vim less wget graphviz unzip tcpdump gdb udev gdisk && \
apt-get clean

# Install Go
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test: generate fmt vet manifests

# Build curve-operator binary
curve-operator: generate fmt vet
go build -o bin/curve-operator main.go
go build -o bin/curve-operator cmd/main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
Expand Down
3 changes: 3 additions & 0 deletions api/v1/curvecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ type CurveClusterSpec struct {

// +optional
Monitor MonitorSpec `json:"monitor,omitempty"`

// +optional
EnableReport bool `json:"enableReport,omitempty"`
}

// CurveClusterStatus defines the observed state of CurveCluster
Expand Down
37 changes: 37 additions & 0 deletions cmd/curve/discover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package curve

import (
"context"
"github.com/opencurve/curve-operator/pkg/clusterd"
"github.com/opencurve/curve-operator/pkg/discover"
"github.com/spf13/cobra"
"k8s.io/klog"
"os"
"time"
)

var (
DiscoverCmd = &cobra.Command{
Use: "discover",
Short: "Discover devices",
Hidden: true, // do not advertise to end users
}

// interval between discovering devices
discoverDevicesInterval time.Duration
)

func init() {
DiscoverCmd.Flags().DurationVar(&discoverDevicesInterval, "discover-interval", 60*time.Minute,
"interval between discovering devices (default 60m)")
DiscoverCmd.Run = startDiscover
}

func startDiscover(cmd *cobra.Command, args []string) {
clusterdContext := clusterd.NewContext()
err := discover.Run(context.TODO(), clusterdContext, discoverDevicesInterval)
if err != nil {
klog.Error(err)
os.Exit(1)
}
}
81 changes: 31 additions & 50 deletions main.go → cmd/curve/operator.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
/*


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 main
package curve

import (
"fmt"
"os"

operatorv1 "github.com/opencurve/curve-operator/api/v1"
"github.com/opencurve/curve-operator/pkg/clusterd"
"github.com/opencurve/curve-operator/pkg/controllers"
"github.com/opencurve/curve-operator/pkg/discover"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

operatorv1 "github.com/opencurve/curve-operator/api/v1"
"github.com/opencurve/curve-operator/pkg/clusterd"
"github.com/opencurve/curve-operator/pkg/controllers"
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")

OperatorCmd = &cobra.Command{
Use: "operator",
// TODO: Rewrite this long message.
Long: `The Curve-Operator is a daemon to deploy Curve and auto it on kubernetes.
It support for Curve storage to natively integrate with cloud-native environments.`,
}
)

func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = operatorv1.AddToScheme(scheme)
// +kubebuilder:scaffold:scheme

options, err := NewCurveOptions()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
options.AddFlags(OperatorCmd.Flags())
OperatorCmd.Run = func(cmd *cobra.Command, args []string) {
setupLog.Error(options.Run(), "failed to run curve-operator")
os.Exit(1)
}
}

type CurveOptions struct {
Expand All @@ -58,32 +58,6 @@ func NewCurveOptions() (*CurveOptions, error) {
}, nil
}

func main() {
opts, err := NewCurveOptions()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}

cmd := &cobra.Command{
Use: "curve-operator",
// TODO: Rewrite this long message.
Long: `The Curve-Operator is a daemon to deploy Curve and auto it on kubernetes.
It support for Curve storage to natively integrate with cloud-native environments.`,
Run: func(cmd *cobra.Command, args []string) {
setupLog.Error(opts.Run(), "failed to run curve-operator")
os.Exit(1)
},
}

opts.AddFlags(cmd.Flags())

if err := cmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}

func (opts *CurveOptions) Run() error {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

Expand Down Expand Up @@ -132,6 +106,13 @@ func (opts *CurveOptions) Run() error {
}
// +kubebuilder:scaffold:builder

// reconcile discover daemonSet
err = discover.ReconcileDiscoveryDaemon()
if err != nil {
setupLog.Error(err, "problem discover")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
11 changes: 11 additions & 0 deletions cmd/curve/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package curve

import (
"github.com/spf13/cobra"
)

var RootCmd = &cobra.Command{
Use: "curve",
Short: "Curve (curve.io) Kubernetes operator and user tools",
Hidden: false,
}
20 changes: 20 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"fmt"
"github.com/opencurve/curve-operator/cmd/curve"
)

func main() {
addCommands()
if err := curve.RootCmd.Execute(); err != nil {
fmt.Printf("curve error: %+v\n", err)
}
}

func addCommands() {
curve.RootCmd.AddCommand(
curve.OperatorCmd,
curve.DiscoverCmd,
)
}
Loading
Loading