Skip to content

Commit a318f74

Browse files
stuggiopenshift-merge-bot[bot]
authored andcommitted
Hash endpoints of services nova depends on
Hashes and watch status updates and deletes for KeystoneEndpoints of the following services: - barbican - cinder - glance - neutron - placement A hash of these services gets added into calc the hash of hashes added as a envvar to the deployments. If there is a change, the deployment/s get restarted to prevent re-use of the previous cached endpoint. Depends-On: openstack-k8s-operators/keystone-operator#588 Jira: OSPRH-16994 Signed-off-by: Martin Schuppert <[email protected]>
1 parent aa8325f commit a318f74

17 files changed

+645
-27
lines changed

api/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.21
44

55
require (
66
github.com/google/go-cmp v0.7.0
7-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250430070919-2ce4eea3a06d
8-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35
7+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250513115636-b549982a5d8f
8+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250508141203-be026d3164f7
99
github.com/robfig/cron/v3 v3.0.1
1010
k8s.io/api v0.29.15
1111
k8s.io/apimachinery v0.29.15

api/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7373
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7474
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7575
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
76-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250430070919-2ce4eea3a06d h1:aphoDw96rkEMGhZJoc+kO3S4o9e/GQfXz/njRPjh+Kw=
77-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250430070919-2ce4eea3a06d/go.mod h1:XywwuHkxaBZA+6QsF+N/3f9ekBq3tH0I/gQZzwL89GU=
78-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35 h1:dczrtvVjeDXUR3OhnUQRhVVnN14KX52qp0KXCulo8pA=
79-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
76+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250513115636-b549982a5d8f h1:b3WGatQCIBoNj8RvbVGNITL9RuQLwkXzXAgt7s/D5zc=
77+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250513115636-b549982a5d8f/go.mod h1:47iJk3vedZWnBkZyNyYij4ma2HjG4l2VCqKz3f+XDkQ=
78+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250508141203-be026d3164f7 h1:c3h1q3fDoit3NmvNL89xUL9A12bJivaTF+IOPEOAwLc=
79+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250508141203-be026d3164f7/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
8080
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8181
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8282
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

controllers/common.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ const (
116116
// NovaCell0DatabaseName - the name of the DB to store the cell schema for
117117
// cell0
118118
NovaCell0DatabaseName = "nova_cell0"
119+
120+
// services nova depends, which are endpoint AppSelector labels
121+
// (mschuppert) - Manial should be added starting Dalmatian
122+
endpointBarbican = "barbican"
123+
endpointCinder = "cinder"
124+
endpointGlance = "glance"
125+
endpointNeutron = "neutron"
126+
endpointPlacement = "placement"
127+
)
128+
129+
var (
130+
endpointList = []string{
131+
endpointBarbican,
132+
endpointCinder,
133+
endpointGlance,
134+
endpointNeutron,
135+
endpointPlacement,
136+
}
119137
)
120138

121139
type conditionsGetter interface {

controllers/novaapi_controller.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ func (r *NovaAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
183183
// detect if something is changed.
184184
hashes := make(map[string]env.Setter)
185185

186+
// hash the endpoint URLs of the services this depends on
187+
// By adding the hash to the hash of hashes being added to the deployment
188+
// allows it to get restarted, in case the endpoint changes and it requires
189+
// the current cached ones to be updated.
190+
endpointUrlsHash, err := keystonev1.GetHashforKeystoneEndpointUrlsForServices(
191+
ctx,
192+
h,
193+
instance.Namespace,
194+
ptr.To(string(endpoint.EndpointInternal)),
195+
endpointList,
196+
)
197+
if err != nil {
198+
return ctrl.Result{}, err
199+
}
200+
hashes["endpointUrlsHash"] = env.SetValue(endpointUrlsHash)
201+
186202
requiredSecretFields := []string{
187203
// TODO(gibi): add keystoneAuthURL here is that is also passed via
188204
// the Secret. Also add DB and MQ user name here too if those are
@@ -787,9 +803,12 @@ func (r *NovaAPIReconciler) ensureKeystoneEndpoint(
787803
if err != nil {
788804
return ctrlResult, err
789805
}
790-
c := endpoint.GetConditions().Mirror(condition.KeystoneEndpointReadyCondition)
791-
if c != nil {
792-
instance.Status.Conditions.Set(c)
806+
807+
if endpoint.ValidateGeneration() {
808+
c := endpoint.GetConditions().Mirror(condition.KeystoneEndpointReadyCondition)
809+
if c != nil {
810+
instance.Status.Conditions.Set(c)
811+
}
793812
}
794813

795814
if (ctrlResult != ctrl.Result{}) {
@@ -923,6 +942,40 @@ func (r *NovaAPIReconciler) findObjectsForSrc(ctx context.Context, src client.Ob
923942
return requests
924943
}
925944

945+
func (r *NovaAPIReconciler) findObjectsWithAppSelectorLabelInNamespace(ctx context.Context, src client.Object) []reconcile.Request {
946+
requests := []reconcile.Request{}
947+
948+
l := log.FromContext(ctx).WithName("Controllers").WithName("NovaAPI")
949+
950+
// if the endpoint has the service label and its in our endpointList, reconcile the CR in the namespace
951+
if svc, ok := src.GetLabels()[common.AppSelector]; ok && util.StringInSlice(svc, endpointList) {
952+
crList := &novav1.NovaAPIList{}
953+
listOps := &client.ListOptions{
954+
Namespace: src.GetNamespace(),
955+
}
956+
err := r.Client.List(ctx, crList, listOps)
957+
if err != nil {
958+
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
959+
return requests
960+
}
961+
962+
for _, item := range crList.Items {
963+
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
964+
965+
requests = append(requests,
966+
reconcile.Request{
967+
NamespacedName: types.NamespacedName{
968+
Name: item.GetName(),
969+
Namespace: item.GetNamespace(),
970+
},
971+
},
972+
)
973+
}
974+
}
975+
976+
return requests
977+
}
978+
926979
// fields to index to reconcile when change
927980
var (
928981
apiWatchFields = []string{
@@ -1043,5 +1096,8 @@ func (r *NovaAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
10431096
Watches(&topologyv1.Topology{},
10441097
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
10451098
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
1099+
Watches(&keystonev1.KeystoneEndpoint{},
1100+
handler.EnqueueRequestsFromMapFunc(r.findObjectsWithAppSelectorLabelInNamespace),
1101+
builder.WithPredicates(keystonev1.KeystoneEndpointStatusChangedPredicate)).
10461102
Complete(r)
10471103
}

controllers/novacompute_controller.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
corev1 "k8s.io/api/core/v1"
2525
"k8s.io/apimachinery/pkg/fields"
2626
"k8s.io/apimachinery/pkg/types"
27+
"k8s.io/utils/ptr"
2728
ctrl "sigs.k8s.io/controller-runtime"
2829
"sigs.k8s.io/controller-runtime/pkg/builder"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -33,8 +34,10 @@ import (
3334
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3435

3536
"github.com/go-logr/logr"
37+
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
3638
common "github.com/openstack-k8s-operators/lib-common/modules/common"
3739
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
40+
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
3841
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
3942
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
4043
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
@@ -158,6 +161,22 @@ func (r *NovaComputeReconciler) Reconcile(ctx context.Context, req ctrl.Request)
158161

159162
hashes := make(map[string]env.Setter)
160163

164+
// hash the endpoint URLs of the services this depends on
165+
// By adding the hash to the hash of hashes being added to the deployment
166+
// allows it to get restarted, in case the endpoint changes and it requires
167+
// the current cached ones to be updated.
168+
endpointUrlsHash, err := keystonev1.GetHashforKeystoneEndpointUrlsForServices(
169+
ctx,
170+
h,
171+
instance.Namespace,
172+
ptr.To(string(endpoint.EndpointInternal)),
173+
endpointList,
174+
)
175+
if err != nil {
176+
return ctrl.Result{}, err
177+
}
178+
hashes["endpointUrlsHash"] = env.SetValue(endpointUrlsHash)
179+
161180
requiredSecretFields := []string{
162181
ServicePasswordSelector,
163182
TransportURLSelector,
@@ -526,6 +545,40 @@ func (r *NovaComputeReconciler) findObjectsForSrc(ctx context.Context, src clien
526545
return requests
527546
}
528547

548+
func (r *NovaComputeReconciler) findObjectsWithAppSelectorLabelInNamespace(ctx context.Context, src client.Object) []reconcile.Request {
549+
requests := []reconcile.Request{}
550+
551+
l := log.FromContext(ctx).WithName("Controllers").WithName("NovaCompute")
552+
553+
// if the endpoint has the service label and its in our endpointList, reconcile the CR in the namespace
554+
if svc, ok := src.GetLabels()[common.AppSelector]; ok && util.StringInSlice(svc, endpointList) {
555+
crList := &novav1.NovaComputeList{}
556+
listOps := &client.ListOptions{
557+
Namespace: src.GetNamespace(),
558+
}
559+
err := r.Client.List(ctx, crList, listOps)
560+
if err != nil {
561+
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
562+
return requests
563+
}
564+
565+
for _, item := range crList.Items {
566+
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
567+
568+
requests = append(requests,
569+
reconcile.Request{
570+
NamespacedName: types.NamespacedName{
571+
Name: item.GetName(),
572+
Namespace: item.GetNamespace(),
573+
},
574+
},
575+
)
576+
}
577+
}
578+
579+
return requests
580+
}
581+
529582
// fields to index to reconcile when change
530583
var (
531584
cmpWatchFields = []string{
@@ -586,5 +639,8 @@ func (r *NovaComputeReconciler) SetupWithManager(mgr ctrl.Manager) error {
586639
Watches(&topologyv1.Topology{},
587640
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
588641
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
642+
Watches(&keystonev1.KeystoneEndpoint{},
643+
handler.EnqueueRequestsFromMapFunc(r.findObjectsWithAppSelectorLabelInNamespace),
644+
builder.WithPredicates(keystonev1.KeystoneEndpointStatusChangedPredicate)).
589645
Complete(r)
590646
}

controllers/novaconductor_controller.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
2727
"k8s.io/apimachinery/pkg/fields"
2828
"k8s.io/apimachinery/pkg/types"
29+
"k8s.io/utils/ptr"
2930
ctrl "sigs.k8s.io/controller-runtime"
3031
"sigs.k8s.io/controller-runtime/pkg/builder"
3132
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -38,9 +39,11 @@ import (
3839
"github.com/go-logr/logr"
3940
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
4041
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
42+
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
4143
common "github.com/openstack-k8s-operators/lib-common/modules/common"
4244
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4345
"github.com/openstack-k8s-operators/lib-common/modules/common/cronjob"
46+
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
4447
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
4548
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
4649
job "github.com/openstack-k8s-operators/lib-common/modules/common/job"
@@ -179,6 +182,22 @@ func (r *NovaConductorReconciler) Reconcile(ctx context.Context, req ctrl.Reques
179182
// detect if something is changed.
180183
hashes := make(map[string]env.Setter)
181184

185+
// hash the endpoint URLs of the services this depends on
186+
// By adding the hash to the hash of hashes being added to the deployment
187+
// allows it to get restarted, in case the endpoint changes and it requires
188+
// the current cached ones to be updated.
189+
endpointUrlsHash, err := keystonev1.GetHashforKeystoneEndpointUrlsForServices(
190+
ctx,
191+
h,
192+
instance.Namespace,
193+
ptr.To(string(endpoint.EndpointInternal)),
194+
endpointList,
195+
)
196+
if err != nil {
197+
return ctrl.Result{}, err
198+
}
199+
hashes["endpointUrlsHash"] = env.SetValue(endpointUrlsHash)
200+
182201
requiredSecretFields := []string{
183202
ServicePasswordSelector,
184203
TransportURLSelector,
@@ -698,6 +717,40 @@ func (r *NovaConductorReconciler) findObjectsForSrc(ctx context.Context, src cli
698717
return requests
699718
}
700719

720+
func (r *NovaConductorReconciler) findObjectsWithAppSelectorLabelInNamespace(ctx context.Context, src client.Object) []reconcile.Request {
721+
requests := []reconcile.Request{}
722+
723+
l := log.FromContext(ctx).WithName("Controllers").WithName("NovaConductor")
724+
725+
// if the endpoint has the service label and its in our endpointList, reconcile the CR in the namespace
726+
if svc, ok := src.GetLabels()[common.AppSelector]; ok && util.StringInSlice(svc, endpointList) {
727+
crList := &novav1.NovaConductorList{}
728+
listOps := &client.ListOptions{
729+
Namespace: src.GetNamespace(),
730+
}
731+
err := r.Client.List(ctx, crList, listOps)
732+
if err != nil {
733+
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
734+
return requests
735+
}
736+
737+
for _, item := range crList.Items {
738+
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
739+
740+
requests = append(requests,
741+
reconcile.Request{
742+
NamespacedName: types.NamespacedName{
743+
Name: item.GetName(),
744+
Namespace: item.GetNamespace(),
745+
},
746+
},
747+
)
748+
}
749+
}
750+
751+
return requests
752+
}
753+
701754
// fields to index to reconcile when change
702755
var (
703756
cdWatchFields = []string{
@@ -834,5 +887,8 @@ func (r *NovaConductorReconciler) SetupWithManager(mgr ctrl.Manager) error {
834887
Watches(&topologyv1.Topology{},
835888
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
836889
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
890+
Watches(&keystonev1.KeystoneEndpoint{},
891+
handler.EnqueueRequestsFromMapFunc(r.findObjectsWithAppSelectorLabelInNamespace),
892+
builder.WithPredicates(keystonev1.KeystoneEndpointStatusChangedPredicate)).
837893
Complete(r)
838894
}

0 commit comments

Comments
 (0)