Skip to content
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
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY server/ server/
COPY templates/ templates/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand All @@ -30,7 +29,6 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/templates/ templates/
USER 65532:65532

ENTRYPOINT ["/manager"]
6 changes: 6 additions & 0 deletions api/v1alpha1/httpbootconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type HTTPBootConfigList struct {
Items []HTTPBootConfig `json:"items"`
}

const (
DefaultIgnitionKey = "ignition"
SystemUUIDIndexKey = "spec.systemUUID"
SystemIPIndexKey = "spec.systemIPs"
)

func init() {
SchemeBuilder.Register(&HTTPBootConfig{}, &HTTPBootConfigList{})
}
77 changes: 0 additions & 77 deletions api/v1alpha1/ipxebootconfig_types.go

This file was deleted.

104 changes: 0 additions & 104 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 3 additions & 93 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var (

const (
// core controllers
ipxeBootConfigController = "ipxebootconfig"
serverBootConfigControllerPxe = "serverbootconfigpxe"
httpBootConfigController = "httpbootconfig"
serverBootConfigControllerHttp = "serverbootconfighttp"
Expand All @@ -57,29 +56,20 @@ func init() {

func main() {
ctx := ctrl.LoggerInto(ctrl.SetupSignalHandler(), setupLog)
defaultIpxeTemplateData := NewDefaultIPXETemplateData()
defaultHttpUKIURL := NewDefaultHTTPBootData()

var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
var enableHTTP2 bool
var ipxeServerAddr string
var imageProxyServerAddr string
var ipxeServiceURL string
var ipxeServiceProtocol string
var ipxeServicePort int
var bootserverAddr string
var imageServerURL string

flag.IntVar(&ipxeServicePort, "ipxe-service-port", 5000, "IPXE Service port to listen on.")
flag.StringVar(&ipxeServiceProtocol, "ipxe-service-protocol", "http", "IPXE Service Protocol.")
flag.StringVar(&ipxeServiceURL, "ipxe-service-url", "", "IPXE Service URL.")
flag.StringVar(&imageServerURL, "image-server-url", "", "OS Image Server URL.")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&ipxeServerAddr, "ipxe-server-address", ":8082", "The address the ipxe-server binds to.")
flag.StringVar(&imageProxyServerAddr, "image-proxy-server-address", ":8083", "The address the image-proxy-server binds to.")
flag.StringVar(&bootserverAddr, "boot-server-address", ":8082", "The address the ipxe-server binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -90,8 +80,6 @@ func main() {

controllers := switches.New(
// core controllers
ipxeBootConfigController,
serverBootConfigControllerPxe,
serverBootConfigControllerHttp,
httpBootConfigController,
)
Expand All @@ -111,17 +99,6 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// set the correct ipxe service URL by getting the address from the environment
var ipxeServiceAddr string
if ipxeServiceURL == "" {
ipxeServiceAddr = os.Getenv("IPXE_SERVER_ADDRESS")
if ipxeServiceAddr == "" {
setupLog.Error(nil, "failed to set the ipxe service URL as no address is provided")
os.Exit(1)
}
ipxeServiceURL = fmt.Sprintf("%s://%s:%d", ipxeServiceProtocol, ipxeServiceAddr, ipxeServicePort)
}

// if the enable-http2 flag is false (the default), http/2 should be disabled
// due to its vulnerabilities. More specifically, disabling http/2 will
// prevent from being vulnerable to the HTTP/2 Stream Cancelation and
Expand Down Expand Up @@ -170,27 +147,6 @@ func main() {
os.Exit(1)
}

if controllers.Enabled(ipxeBootConfigController) {
if err = (&controller.IPXEBootConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IPXEBootConfig")
os.Exit(1)
}
}

if controllers.Enabled(serverBootConfigControllerPxe) {
if err = (&controller.ServerBootConfigurationPXEReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
IPXEServiceURL: ipxeServiceURL,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ServerBootConfigPxe")
os.Exit(1)
}
}

if controllers.Enabled(serverBootConfigControllerHttp) {
if err = (&controller.ServerBootConfigurationHTTPReconciler{
Client: mgr.GetClient(),
Expand Down Expand Up @@ -223,31 +179,18 @@ func main() {
os.Exit(1)
}

if err := IndexIPXEBootConfigBySystemUUID(ctx, mgr); err != nil {
setupLog.Error(err, "unable to set up indexer for IPXEBootConfig SystemUUID")
os.Exit(1)
}

if err := IndexHTTPBootConfigBySystemUUID(ctx, mgr); err != nil {
setupLog.Error(err, "unable to set up indexer for HTTPBootConfig SystemUUID")
os.Exit(1)
}

if err := IndexIPXEBootConfigBySystemIPs(ctx, mgr); err != nil {
setupLog.Error(err, "unable to set up indexer for IPXEBootConfig SystemIPs")
os.Exit(1)
}

if err := IndexHTTPBootConfigBySystemIPs(ctx, mgr); err != nil {
setupLog.Error(err, "unable to set up indexer for HTTPBootConfig SystemIP")
os.Exit(1)
}

setupLog.Info("starting boot-server")
go bootserver.RunBootServer(ipxeServerAddr, ipxeServiceURL, mgr.GetClient(), serverLog.WithName("bootserver"), *defaultIpxeTemplateData, *defaultHttpUKIURL)

setupLog.Info("starting image-proxy-server")
go bootserver.RunImageProxyServer(imageProxyServerAddr, mgr.GetClient(), serverLog.WithName("imageproxyserver"))
go bootserver.RunBootServer(mgr.GetClient(), serverLog.WithName("bootserver"), bootserverAddr, *defaultHttpUKIURL)

setupLog.Info("starting manager")
if err := mgr.Start(ctx); err != nil {
Expand All @@ -256,29 +199,6 @@ func main() {
}
}

func IndexIPXEBootConfigBySystemUUID(ctx context.Context, mgr ctrl.Manager) error {
return mgr.GetFieldIndexer().IndexField(
ctx,
&bootv1alpha1.IPXEBootConfig{},
bootv1alpha1.SystemUUIDIndexKey,
func(Obj client.Object) []string {
ipxeBootConfig := Obj.(*bootv1alpha1.IPXEBootConfig)
return []string{ipxeBootConfig.Spec.SystemUUID}
},
)
}

func IndexIPXEBootConfigBySystemIPs(ctx context.Context, mgr ctrl.Manager) error {
return mgr.GetFieldIndexer().IndexField(
ctx, &bootv1alpha1.IPXEBootConfig{},
bootv1alpha1.SystemIPIndexKey,
func(Obj client.Object) []string {
ipxeBootConfig := Obj.(*bootv1alpha1.IPXEBootConfig)
return ipxeBootConfig.Spec.SystemIPs
},
)
}

func IndexHTTPBootConfigBySystemUUID(ctx context.Context, mgr ctrl.Manager) error {
return mgr.GetFieldIndexer().IndexField(
ctx,
Expand All @@ -303,16 +223,6 @@ func IndexHTTPBootConfigBySystemIPs(ctx context.Context, mgr ctrl.Manager) error
)
}

func NewDefaultIPXETemplateData() *bootserver.IPXETemplateData {
var cfg bootserver.IPXETemplateData
flag.StringVar(&cfg.KernelURL, "default-kernel-url", "", "Default URL for the kernel")
flag.StringVar(&cfg.InitrdURL, "default-initrd-url", "", "Default URL for the initrd")
flag.StringVar(&cfg.SquashfsURL, "default-squashfs-url", "", "Default URL for the squashfs")
flag.StringVar(&cfg.IPXEServerURL, "default-ipxe-server-url", "", "Default IPXE Server URL to while generating ipxe-script")

return &cfg
}

func NewDefaultHTTPBootData() *string {
var defaultUKIURL string
flag.StringVar(&defaultUKIURL, "default-httpboot-uki-url", "", "Default UKI URL for http boot")
Expand Down
Loading