forked from openstack-k8s-operators/swift-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DNSData entries for SwiftStorage service pods
Storage service hostnames need to be resolvable on the dataplane nodes as well. They are used within the Swift rings to be able to allow node IP changes without updating and redistributing Swift rings. This patch creates DNSData entries for every storage service pod, similar to [1]. It only creates DNS for the storage network, as this is the only one that should be used within the storage backend services. There is no delete function to scale down, as we don't support scaling down for SwiftStorage instances. However, the created DNSData CRs are owned by the SwiftStorage instance, thus being deleted properly if the instance is deleted. [1] openstack-k8s-operators/ovn-operator#154
- Loading branch information
Showing
7 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package swiftstorage | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" | ||
"github.com/openstack-k8s-operators/lib-common/modules/common/helper" | ||
swiftv1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
// DNSData - Create DNS entry that openstack dnsmasq will resolve | ||
func DNSData( | ||
ctx context.Context, | ||
helper *helper.Helper, | ||
hostName string, | ||
ip string, | ||
instance *swiftv1.SwiftStorage, | ||
swiftPod corev1.Pod, | ||
serviceLabels map[string]string, | ||
) error { | ||
dnsHostCname := infranetworkv1.DNSHost{ | ||
IP: ip, | ||
Hostnames: []string{ | ||
hostName, | ||
}, | ||
} | ||
|
||
// Create DNSData object | ||
dnsData := &infranetworkv1.DNSData{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: swiftPod.Name, | ||
Namespace: swiftPod.Namespace, | ||
Labels: serviceLabels, | ||
}, | ||
} | ||
dnsHosts := []infranetworkv1.DNSHost{dnsHostCname} | ||
|
||
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), dnsData, func() error { | ||
dnsData.Spec.Hosts = dnsHosts | ||
// TODO: use value from DNSMasq instance instead of hardcode | ||
dnsData.Spec.DNSDataLabelSelectorValue = "dnsdata" | ||
err := controllerutil.SetControllerReference(helper.GetBeforeObject(), dnsData, helper.GetScheme()) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error creating DNSData %s: %w", dnsData.Name, err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters