Skip to content

Commit

Permalink
Merge pull request #161 from rabi/bind_ip
Browse files Browse the repository at this point in the history
Use bind_ip instead of bind_host
  • Loading branch information
openshift-merge-bot[bot] authored Mar 5, 2024
2 parents c0028cc + 48ae3f7 commit 0c49931
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 7 deletions.
7 changes: 7 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- apiGroups:
- ""
resources:
Expand Down
7 changes: 6 additions & 1 deletion controllers/swiftproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type SwiftProxyReconciler struct {
//+kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
//+kubebuilder:rbac:groups=memcached.openstack.org,resources=memcacheds,verbs=get;list;watch;
//+kubebuilder:rbac:groups=barbican.openstack.org,resources=barbicanapis,verbs=get;list;watch
//+kubebuilder:rbac:groups=core,resources=nodes,verbs=get;list

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down Expand Up @@ -455,7 +456,10 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage)

bindIP, err := swift.GetBindIP(helper)
if err != nil {
return ctrl.Result{}, err
}
// Create a Secret populated with content from templates/
tpl := swiftproxy.SecretTemplates(
instance,
Expand All @@ -464,6 +468,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
keystoneInternalURL,
password,
instance.Spec.MemcachedServers,
bindIP,
secretRef,
)
err = secret.EnsureSecrets(ctx, helper, instance, tpl, &envVars)
Expand Down
11 changes: 9 additions & 2 deletions controllers/swiftstorage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/client-go/kubernetes"

swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
"github.com/openstack-k8s-operators/swift-operator/pkg/swift"
"github.com/openstack-k8s-operators/swift-operator/pkg/swiftstorage"

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
Expand Down Expand Up @@ -76,6 +77,7 @@ type Netconfig struct {
//+kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
//+kubebuilder:rbac:groups=memcached.openstack.org,resources=memcacheds,verbs=get;list;watch;
//+kubebuilder:rbac:groups=network.openstack.org,resources=dnsdata,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core,resources=nodes,verbs=get;list

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down Expand Up @@ -167,8 +169,12 @@ func (r *SwiftStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request
serviceLabels := swiftstorage.Labels()
envVars := make(map[string]env.Setter)

bindIP, err := swift.GetBindIP(helper)
if err != nil {
return ctrl.Result{}, err
}
// Create a ConfigMap populated with content from templates/
tpl := swiftstorage.ConfigMapTemplates(instance, serviceLabels, instance.Spec.MemcachedServers)
tpl := swiftstorage.ConfigMapTemplates(instance, serviceLabels, instance.Spec.MemcachedServers, bindIP)
err = configmap.EnsureConfigMaps(ctx, helper, instance, tpl, &envVars)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -338,7 +344,8 @@ func getPodIPInNetwork(swiftPod corev1.Pod, namespace string, networkAttachment
networkName := fmt.Sprintf("%s/%s", namespace, networkAttachment)
netStat, err := networkattachment.GetNetworkStatusFromAnnotation(swiftPod.Annotations)
if err != nil {
err = fmt.Errorf("Error while getting the Network Status for pod %s: %v", swiftPod.Name, err)
err = fmt.Errorf("Error while getting the Network Status for pod %s: %w",
swiftPod.Name, err)
return "", err
}
for _, net := range netStat {
Expand Down
23 changes: 22 additions & 1 deletion pkg/swift/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ limitations under the License.
package swift

import (
"context"
"math/rand"
"strings"

"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/affinity"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
corev1 "k8s.io/api/core/v1"
"math/rand"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func GetSecurityContext() corev1.SecurityContext {
Expand Down Expand Up @@ -69,3 +74,19 @@ func GetPodAffinity(componentName string) *corev1.Affinity {
corev1.LabelHostname,
)
}

// GetBindIP - Returns bind ip for services for ipv4 and ipv6.
func GetBindIP(helper *helper.Helper) (string, error) {
nodes, err := helper.GetKClient().CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return "0.0.0.0", err
}
for _, node := range nodes.Items {
for _, address := range node.Status.Addresses {
if address.Type == "InternalIP" && strings.Contains(address.Address, ":") {
return "::", nil
}
}
}
return "0.0.0.0", nil
}
2 changes: 2 additions & 0 deletions pkg/swiftproxy/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func SecretTemplates(
keystoneInternalURL string,
password string,
memcachedServers string,
bindIP string,
secretRef string,
) []util.Template {
templateParameters := make(map[string]interface{})
Expand All @@ -41,6 +42,7 @@ func SecretTemplates(
templateParameters["KeystonePublicURL"] = keystonePublicURL
templateParameters["KeystoneInternalURL"] = keystoneInternalURL
templateParameters["MemcachedServers"] = memcachedServers
templateParameters["BindIP"] = bindIP
templateParameters["SecretRef"] = secretRef

// create httpd vhost template parameters
Expand Down
7 changes: 6 additions & 1 deletion pkg/swiftstorage/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ package swiftstorage

import (
"fmt"

"github.com/openstack-k8s-operators/lib-common/modules/common/util"
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
)

func ConfigMapTemplates(instance *swiftv1beta1.SwiftStorage, labels map[string]string, memcachedServers string) []util.Template {
func ConfigMapTemplates(instance *swiftv1beta1.SwiftStorage,
labels map[string]string,
memcachedServers string,
bindIP string) []util.Template {
templateParameters := make(map[string]interface{})
templateParameters["MemcachedServers"] = memcachedServers
templateParameters["BindIP"] = bindIP

customData := map[string]string{}
for key, data := range instance.Spec.DefaultConfigOverwrite {
Expand Down
2 changes: 1 addition & 1 deletion templates/swiftproxy/config/00-proxy-server.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[DEFAULT]
bind_host = localhost
bind_ip = {{ .BindIP }}
bind_port = 8081

[pipeline:main]
Expand Down
1 change: 1 addition & 0 deletions templates/swiftstorage/config/00-account-server.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[DEFAULT]
bind_ip = {{ .BindIP }}
bind_port = 6202

[pipeline:main]
Expand Down
1 change: 1 addition & 0 deletions templates/swiftstorage/config/00-container-server.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[DEFAULT]
bind_ip = {{ .BindIP }}
bind_port = 6201

[pipeline:main]
Expand Down
1 change: 1 addition & 0 deletions templates/swiftstorage/config/00-object-server.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[DEFAULT]
bind_ip = {{ .BindIP }}
bind_port = 6200

[pipeline:main]
Expand Down
1 change: 0 additions & 1 deletion tests/functional/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var (
k8sClient client.Client
testEnv *envtest.Environment
th *TestHelper
ctx context.Context
cancel context.CancelFunc
logger logr.Logger
)
Expand Down

0 comments on commit 0c49931

Please sign in to comment.