Skip to content

Commit b907b20

Browse files
mdboothmandre
authored andcommitted
Add cluster-capi-operator integration
1 parent d6627ed commit b907b20

File tree

3,954 files changed

+1298814
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,954 files changed

+1298814
-3
lines changed

Dockerfile.rhel

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,26 @@ ENV GOPROXY=$goproxy
2424
COPY ./ ./
2525

2626
# Build
27-
ARG package=.
2827
ARG ARCH
2928
ARG ldflags
3029

31-
# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
30+
WORKDIR /workspace/openshift
3231
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
3332
go build -ldflags "${ldflags} -extldflags '-static'" \
34-
-o manager ${package}
33+
-o ../infracluster-controller cmd/manager.go
34+
35+
WORKDIR /workspace
36+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
37+
go build -ldflags "${ldflags} -extldflags '-static'" \
38+
-o manager
3539

3640
# Production image
3741
FROM registry.ci.openshift.org/ocp/4.16:base
3842
WORKDIR /
3943
COPY --from=builder /workspace/manager .
44+
COPY --from=builder /workspace/infracluster-controller .
45+
COPY ./openshift/manifests ./manifests
46+
4047
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
4148
USER 65532
4249
ENTRYPOINT ["/manager"]

openshift/Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2023 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
manifests_dir ?= ./manifests
16+
manifests_prefix ?= 0000_30_cluster-api-provider-openstack_
17+
18+
TOOLS_DIR=../hack/tools
19+
KUSTOMIZE=$(TOOLS_DIR)/bin/kustomize
20+
CONTROLLER_GEN=$(TOOLS_DIR)/bin/controller-gen
21+
22+
define manifest_name
23+
$(addsuffix ".yaml",$(addprefix $(manifests_dir)/$(manifests_prefix),$(1)))
24+
endef
25+
26+
manifest_names = 00_credentials-request 04_infrastructure-components
27+
infrastructure_components = kustomize/cluster-capi-configmap/infrastructure-components.yaml
28+
infracluster_role = kustomize/infracluster-controller/role.yaml
29+
30+
.PHONY: all_manifests
31+
all_manifests: $(foreach m,$(manifest_names),$(call manifest_name,$(m)))
32+
33+
$(call manifest_name,00_credentials-request): $(KUSTOMIZE) ALWAYS | $(manifests_dir)
34+
$(KUSTOMIZE) build kustomize/credentials-request > $@
35+
36+
$(infrastructure_components): $(KUSTOMIZE) $(infracluster_role) ALWAYS
37+
$(KUSTOMIZE) build kustomize/infrastructure-components > $@
38+
39+
$(call manifest_name,04_infrastructure-components): $(KUSTOMIZE) $(infrastructure_components) ALWAYS | $(manifests_dir)
40+
$(KUSTOMIZE) build kustomize/cluster-capi-configmap > $@
41+
42+
$(infracluster_role): $(CONTROLLER_GEN) ALWAYS
43+
$(CONTROLLER_GEN) rbac:roleName=infracluster-controller paths=./pkg/infracluster_controller output:stdout > $@
44+
45+
$(manifests_dir):
46+
mkdir -p $@
47+
48+
$(KUSTOMIZE):
49+
$(MAKE) -C $(TOOLS_DIR) bin/kustomize
50+
51+
$(CONTROLLER_GEN):
52+
$(MAKE) -C $(TOOLS_DIR) bin/controller-gen
53+
54+
.PHONY: ALWAYS
55+
ALWAYS:

openshift/cmd/manager.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"flag"
21+
"os"
22+
23+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
24+
// to ensure that exec-entrypoint and run can make use of them.
25+
_ "k8s.io/client-go/plugin/pkg/client/auth"
26+
27+
"k8s.io/apimachinery/pkg/fields"
28+
ctrl "sigs.k8s.io/controller-runtime"
29+
"sigs.k8s.io/controller-runtime/pkg/cache"
30+
"sigs.k8s.io/controller-runtime/pkg/controller"
31+
"sigs.k8s.io/controller-runtime/pkg/healthz"
32+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
33+
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
34+
35+
//+kubebuilder:scaffold:imports
36+
37+
openshiftconfig "github.com/openshift/api/config/v1"
38+
mapi "github.com/openshift/api/machine/v1beta1"
39+
corev1 "k8s.io/api/core/v1"
40+
41+
"github.com/openshift/cluster-api-provider-openstack/openshift/pkg/infracluster_controller"
42+
caposcheme "github.com/openshift/cluster-api-provider-openstack/openshift/pkg/scheme"
43+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/scope"
44+
"sigs.k8s.io/controller-runtime/pkg/client"
45+
)
46+
47+
var (
48+
scheme = caposcheme.DefaultScheme()
49+
setupLog = ctrl.Log.WithName("setup")
50+
)
51+
52+
func main() {
53+
var metricsAddr string
54+
var enableLeaderElection bool
55+
var probeAddr string
56+
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
57+
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
58+
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
59+
"Enable leader election for controller manager. "+
60+
"Enabling this will ensure there is only one active controller manager.")
61+
opts := zap.Options{
62+
Development: true,
63+
}
64+
opts.BindFlags(flag.CommandLine)
65+
flag.Parse()
66+
67+
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
68+
69+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
70+
Scheme: scheme,
71+
Metrics: metricsserver.Options{BindAddress: metricsAddr},
72+
HealthProbeBindAddress: probeAddr,
73+
LeaderElection: enableLeaderElection,
74+
LeaderElectionID: "infracluster-leader-election-capo",
75+
LeaderElectionNamespace: infracluster_controller.CAPINamespace,
76+
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
77+
// when the Manager ends. This requires the binary to immediately end when the
78+
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
79+
// speeds up voluntary leader transitions as the new leader don't have to wait
80+
// LeaseDuration time first.
81+
//
82+
// In the default scaffold provided, the program ends immediately after
83+
// the manager stops, so would be fine to enable this option. However,
84+
// if you are doing or is intended to do any operation such as perform cleanups
85+
// after the manager stops then its usage might be unsafe.
86+
LeaderElectionReleaseOnCancel: true,
87+
88+
Cache: cache.Options{
89+
// Restrict namespaced watches to the Cluster API namespace
90+
DefaultNamespaces: map[string]cache.Config{
91+
infracluster_controller.CAPINamespace: {},
92+
},
93+
94+
ByObject: map[client.Object]cache.ByObject{
95+
// MAPI Machines are in their own namespace
96+
&mapi.Machine{}: {
97+
Namespaces: map[string]cache.Config{
98+
infracluster_controller.MAPINamespace: {},
99+
},
100+
},
101+
102+
// We only need to watch a single cluster operator
103+
&openshiftconfig.ClusterOperator{}: {
104+
Field: fields.OneTermEqualSelector("metadata.name", infracluster_controller.ClusterOperatorName),
105+
},
106+
107+
// We only need to watch a single secret
108+
&corev1.Secret{}: {
109+
Namespaces: map[string]cache.Config{
110+
infracluster_controller.CAPINamespace: {},
111+
},
112+
Field: fields.OneTermEqualSelector("metadata.name", infracluster_controller.CredentialsSecretName),
113+
},
114+
},
115+
},
116+
})
117+
if err != nil {
118+
setupLog.Error(err, "unable to start manager")
119+
os.Exit(1)
120+
}
121+
122+
//+kubebuilder:scaffold:builder
123+
124+
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
125+
setupLog.Error(err, "unable to set up health check")
126+
os.Exit(1)
127+
}
128+
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
129+
setupLog.Error(err, "unable to set up ready check")
130+
os.Exit(1)
131+
}
132+
133+
if err := (&infracluster_controller.OpenShiftClusterReconciler{
134+
Client: mgr.GetClient(),
135+
Recorder: mgr.GetEventRecorderFor("openshiftcluster-controller"),
136+
ScopeFactory: scope.ScopeFactory,
137+
}).SetupWithManager(mgr, controller.Options{}); err != nil {
138+
setupLog.Error(err, "unable to create controller", "controller", "OpenStackCluster")
139+
os.Exit(1)
140+
}
141+
142+
setupLog.Info("starting manager")
143+
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
144+
setupLog.Error(err, "problem running manager")
145+
os.Exit(1)
146+
}
147+
}

openshift/go.mod

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
module github.com/openshift/cluster-api-provider-openstack/openshift
2+
3+
go 1.20
4+
5+
require (
6+
github.com/go-logr/logr v1.2.4
7+
github.com/gophercloud/gophercloud v1.7.0
8+
github.com/openshift/api v0.0.0-20231003083825-c3f7566f6ef6
9+
k8s.io/api v0.28.2
10+
k8s.io/apimachinery v0.28.2
11+
k8s.io/client-go v0.28.1
12+
sigs.k8s.io/cluster-api v1.5.2
13+
sigs.k8s.io/cluster-api-provider-openstack v0.8.0
14+
sigs.k8s.io/controller-runtime v0.16.2
15+
)
16+
17+
require (
18+
github.com/beorn7/perks v1.0.1 // indirect
19+
github.com/blang/semver v3.5.1+incompatible // indirect
20+
github.com/blang/semver/v4 v4.0.0 // indirect
21+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
22+
github.com/davecgh/go-spew v1.1.1 // indirect
23+
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
24+
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
25+
github.com/fsnotify/fsnotify v1.6.0 // indirect
26+
github.com/go-logr/zapr v1.2.4 // indirect
27+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
28+
github.com/go-openapi/jsonreference v0.20.2 // indirect
29+
github.com/go-openapi/swag v0.22.3 // indirect
30+
github.com/gogo/protobuf v1.3.2 // indirect
31+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
32+
github.com/golang/mock v1.6.0 // indirect
33+
github.com/golang/protobuf v1.5.3 // indirect
34+
github.com/google/gnostic-models v0.6.8 // indirect
35+
github.com/google/go-cmp v0.5.9 // indirect
36+
github.com/google/gofuzz v1.2.0 // indirect
37+
github.com/google/uuid v1.3.0 // indirect
38+
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 // indirect
39+
github.com/hashicorp/go-uuid v1.0.3 // indirect
40+
github.com/imdario/mergo v0.3.15 // indirect
41+
github.com/josharian/intern v1.0.0 // indirect
42+
github.com/json-iterator/go v1.1.12 // indirect
43+
github.com/mailru/easyjson v0.7.7 // indirect
44+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
45+
github.com/mitchellh/go-homedir v1.1.0 // indirect
46+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
47+
github.com/modern-go/reflect2 v1.0.2 // indirect
48+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
49+
github.com/pkg/errors v0.9.1 // indirect
50+
github.com/prometheus/client_golang v1.17.0 // indirect
51+
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
52+
github.com/prometheus/common v0.44.0 // indirect
53+
github.com/prometheus/procfs v0.11.1 // indirect
54+
github.com/spf13/pflag v1.0.5 // indirect
55+
go.uber.org/multierr v1.11.0 // indirect
56+
go.uber.org/zap v1.25.0 // indirect
57+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
58+
golang.org/x/net v0.17.0 // indirect
59+
golang.org/x/oauth2 v0.13.0 // indirect
60+
golang.org/x/sys v0.13.0 // indirect
61+
golang.org/x/term v0.13.0 // indirect
62+
golang.org/x/text v0.13.0 // indirect
63+
golang.org/x/time v0.3.0 // indirect
64+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
65+
google.golang.org/appengine v1.6.7 // indirect
66+
google.golang.org/protobuf v1.31.0 // indirect
67+
gopkg.in/inf.v0 v0.9.1 // indirect
68+
gopkg.in/yaml.v2 v2.4.0 // indirect
69+
gopkg.in/yaml.v3 v3.0.1 // indirect
70+
k8s.io/apiextensions-apiserver v0.28.0 // indirect
71+
k8s.io/component-base v0.28.1 // indirect
72+
k8s.io/klog/v2 v2.100.1 // indirect
73+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
74+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
75+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
76+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
77+
sigs.k8s.io/yaml v1.3.0 // indirect
78+
)
79+
80+
replace sigs.k8s.io/cluster-api-provider-openstack => ../

0 commit comments

Comments
 (0)