Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#853 from slagle/certs-from
Browse files Browse the repository at this point in the history
Add CertsFrom and EDPMServiceName to Service
  • Loading branch information
openshift-merge-bot[bot] authored Apr 25, 2024
2 parents b2537b4 + 1706a30 commit f9f807b
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ spec:
type: boolean
caCerts:
type: string
certsFrom:
type: string
configMaps:
items:
type: string
Expand All @@ -46,6 +48,8 @@ spec:
type: array
deployOnAllNodeSets:
type: boolean
edpmServiceName:
type: string
openStackAnsibleEERunnerImage:
type: string
play:
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ type OpenStackDataPlaneServiceSpec struct {
// +kubebuilder:validation:Optional
OpenStackAnsibleEERunnerImage string `json:"openStackAnsibleEERunnerImage,omitempty" yaml:"openStackAnsibleEERunnerImage,omitempty"`

// CertsFrom - Service name used to obtain TLSCert and CACerts data. If both
// CertsFrom and either TLSCert or CACerts is set, then those fields take
// precedence.
// +kubebuilder:validation:Optional
CertsFrom string `json:"certsFrom,omitempty" yaml:"certsFrom,omitempty"`

// AddCertMounts - Whether to add cert mounts
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Expand All @@ -90,6 +96,10 @@ type OpenStackDataPlaneServiceSpec struct {
// ContainerImages struct field names from
// github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1
ContainerImageFields []string `json:"containerImageFields,omitempty" yaml:"containerImageFields,omitempty"`

// EDPMServiceName - name to use for edpm_service_name ansible variable
// +kubebuilder:validation:Optional
EDPMServiceName string `json:"edpmServiceName,omitempty" yaml:"edpmServiceName,omitempty"`
}

// OpenStackDataPlaneServiceStatus defines the observed state of OpenStackDataPlaneService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ spec:
type: boolean
caCerts:
type: string
certsFrom:
type: string
configMaps:
items:
type: string
Expand All @@ -46,6 +48,8 @@ spec:
type: array
deployOnAllNodeSets:
type: boolean
edpmServiceName:
type: string
openStackAnsibleEERunnerImage:
type: string
play:
Expand Down
10 changes: 10 additions & 0 deletions docs/assemblies/custom_resources.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneSer
| string
| false
| certsFrom
| CertsFrom - Service name used to obtain TLSCert and CACerts data. If both CertsFrom and either TLSCert or CACerts is set, then those fields take precedence.
| string
| false
| addCertMounts
| AddCertMounts - Whether to add cert mounts
| bool
Expand All @@ -348,6 +353,11 @@ OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneSer
| ContainerImageFields - list of container image fields names that this service deploys. The field names should match the ContainerImages struct field names from github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1
| []string
| false
| edpmServiceName
| EDPMServiceName - name to use for edpm_service_name ansible variable
| string
| false
|===
<<custom-resources,Back to Custom Resources>>
Expand Down
12 changes: 12 additions & 0 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sort"
"strconv"

slices "golang.org/x/exp/slices"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -224,6 +225,17 @@ func (d *Deployer) addCertMounts(
if err != nil {
return nil, err
}

if service.Spec.CertsFrom != "" && service.Spec.TLSCert == nil && service.Spec.CACerts == "" {
if slices.Contains(services, service.Spec.CertsFrom) {
continue
}
service, err = GetService(d.Ctx, d.Helper, service.Spec.CertsFrom)
if err != nil {
return nil, err
}
}

if service.Spec.TLSCert != nil {
log.Info("Mounting TLS cert for service", "service", svc)
volMounts := storage.VolMounts{}
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ func AnsibleExecution(
util.LogForObject(helper,
fmt.Sprintf("for service %s, substituting existing ansible play host with '%s'.", service.Name, nodeSet.GetName()), ansibleEE)
}
ansibleEE.Spec.ExtraVars["edpm_service_name"] = json.RawMessage([]byte(fmt.Sprintf("\"%s\"", service.Name)))
if service.Spec.EDPMServiceName != "" {
ansibleEE.Spec.ExtraVars["edpm_service_name"] = json.RawMessage([]byte(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceName)))
} else {
ansibleEE.Spec.ExtraVars["edpm_service_name"] = json.RawMessage([]byte(fmt.Sprintf("\"%s\"", service.Name)))
}

for sshKeyNodeName, sshKeySecret := range sshKeySecrets {
if service.Spec.DeployOnAllNodeSets {
Expand Down
16 changes: 16 additions & 0 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ func CreateDataplaneService(name types.NamespacedName, globalService bool) *unst
return th.CreateUnstructured(raw)
}

// Create an OpenStackDataPlaneService with a given NamespacedName, and a given unstructured spec
func CreateDataPlaneServiceFromSpec(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
raw := map[string]interface{}{

"apiVersion": "dataplane.openstack.org/v1beta1",
"kind": "OpenStackDataPlaneService",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
return th.CreateUnstructured(raw)
}

// Build CustomServiceImageSpec struct with empty `Nodes` list
func CustomServiceImageSpec() map[string]interface{} {

Expand Down Expand Up @@ -96,6 +111,7 @@ func DefaultDataPlaneNodeSetSpec(nodeSetName string) map[string]interface{} {
return map[string]interface{}{
"services": []string{
"foo-service",
"foo-update-service",
"global-service",
},
"nodeTemplate": map[string]interface{}{
Expand Down
34 changes: 29 additions & 5 deletions tests/functional/openstackdataplanedeployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
var dataplaneNetConfigName types.NamespacedName
var dataplaneMultiNodesetDeploymentName types.NamespacedName
var dataplaneServiceName types.NamespacedName
var dataplaneUpdateServiceName types.NamespacedName
var dataplaneGlobalServiceName types.NamespacedName

BeforeEach(func() {
Expand Down Expand Up @@ -79,6 +80,10 @@ var _ = Describe("Dataplane Deployment Test", func() {
Namespace: namespace,
Name: "foo-service",
}
dataplaneUpdateServiceName = types.NamespacedName{
Namespace: namespace,
Name: "foo-update-service",
}
dataplaneGlobalServiceName = types.NamespacedName{
Name: "global-service",
Namespace: namespace,
Expand Down Expand Up @@ -106,9 +111,14 @@ var _ = Describe("Dataplane Deployment Test", func() {
DeferCleanup(th.DeleteInstance, th.CreateSecret(ceilometerConfigSecretName, map[string][]byte{
"fake_keys": []byte("blih"),
}))
// DefaultDataPlanenodeSetSpec comes with two mock services, one marked for deployment on all nodesets
// DefaultDataPlanenodeSetSpec comes with three mock services
// default service
CreateDataplaneService(dataplaneServiceName, false)
// marked for deployment on all nodesets
CreateDataplaneService(dataplaneGlobalServiceName, true)
// with EDPMServiceName set
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceName": "foo-service"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down Expand Up @@ -188,8 +198,12 @@ var _ = Describe("Dataplane Deployment Test", func() {
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded

g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
g.Expect(ansibleEE.Spec.ExtraVars).To(HaveKey("edpm_override_hosts"))
if service.Spec.EDPMServiceName != "" {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceName)))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
}
if service.Spec.DeployOnAllNodeSets {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal("\"all\""))
} else {
Expand Down Expand Up @@ -242,9 +256,11 @@ var _ = Describe("Dataplane Deployment Test", func() {
Namespace: namespace,
}

// Two services on both nodesets
// Three services on both nodesets
CreateDataplaneService(dataplaneServiceName, false)
CreateDataplaneService(dataplaneGlobalServiceName, true)
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceName": "foo-service"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down Expand Up @@ -393,7 +409,11 @@ var _ = Describe("Dataplane Deployment Test", func() {
}
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
if service.Spec.EDPMServiceName != "" {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceName)))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
}
if service.Spec.DeployOnAllNodeSets {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal("\"all\""))
}
Expand Down Expand Up @@ -426,7 +446,11 @@ var _ = Describe("Dataplane Deployment Test", func() {
}
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
if service.Spec.EDPMServiceName != "" {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceName)))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_name"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
}
}, th.Timeout, th.Interval).Should(Succeed())
}

Expand Down

0 comments on commit f9f807b

Please sign in to comment.