Skip to content

Commit

Permalink
Merge pull request #18 from amoniacou/add-routes
Browse files Browse the repository at this point in the history
Routes support
  • Loading branch information
simonoff authored Sep 20, 2024
2 parents 05c3f01 + 4395e46 commit 43c08a8
Show file tree
Hide file tree
Showing 21 changed files with 1,149 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## Unreleased

- Support for routes on mailgun
- Support for adding an additional DNS records to make external DNS set all records at once and set a proper owner if you need an additional DNS entries

## 1.2.7

- fix saving status of domain on mailgun
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ resources:
group: externaldns
kind: DNSEndpoint
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: mailgun.com
group: domain
kind: Route
path: github.com/amoniacou/mailgun-operator/api/domain/v1
version: v1
version: "3"
9 changes: 5 additions & 4 deletions api/domain/v1/domain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1
import (
"github.com/mailgun/mailgun-go/v4"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/external-dns/endpoint"
)

type DnsRecord struct {
Expand Down Expand Up @@ -51,8 +52,11 @@ const (
type DomainSpec struct {
// Domain is a domain name which we need to create on Mailgun
Domain string `json:"domain"`

// Support for External-DNS
ExternalDNS *bool `json:"external_dns,omitempty"`
ExternalDNS *bool `json:"external_dns,omitempty"`
ExternalDNSRecords []endpoint.Endpoint `json:"external_dns_records,omitempty"`

// See https://documentation.mailgun.com/en/latest/api-domains.html#domains
WebScheme *WebSchemeType `json:"web_scheme,omitempty"`
DKIMKeySize *int `json:"dkim_key_size,omitempty"`
Expand All @@ -66,13 +70,10 @@ type DomainSpec struct {
// Export SMTP or API credentials to a secret
ExportCredentials *bool `json:"export_credentials,omitempty"`
// Export SMTP credentials to a secret
// +kubebuilder:validation:RequiredIf=ExportCredentials==true
ExportSecretName *string `json:"export_secret_name,omitempty"`
// Export secret key for login
// +kubebuilder:validation:RequiredIf=ExportCredentials==true
ExportSecretLoginKey *string `json:"export_secret_login_key,omitempty"`
// Export secret key for password
// +kubebuilder:validation:RequiredIf=ExportCredentials==true
ExportSecretPasswordKey *string `json:"export_secret_password_key,omitempty"`

// Force validation of MX records for receiving mail
Expand Down
71 changes: 71 additions & 0 deletions api/domain/v1/route_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2024 Amoniac OU.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// RouteSpec defines the desired state of Route
type RouteSpec struct {
// Description of the route
// +kubebuilder:validation:required
Description string `json:"description"`
// Matching expression for the route
// +kubebuilder:validation:required
Expression string `json:"expression"`
// Action to be taken when the route matches an incoming email
// +kubebuilder:validation:required
Actions []string `json:"action"`
// Priority of route
// Smaller number indicates higher priority. Higher priority routes are handled first.
// +optional
Priority *int `json:"priority"`
}

// RouteStatus defines the observed state of Route
type RouteStatus struct {
// ID of created route on mailgun
RouteID *string `json:"route_id,omitempty"`
// Mailgun error message if any error occurred during route creation or deletion
MailgunError *string `json:"mailgun_error,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Route is the Schema for the routes API
type Route struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RouteSpec `json:"spec,omitempty"`
Status RouteStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// RouteList contains a list of Route
type RouteList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Route `json:"items"`
}

func init() {
SchemeBuilder.Register(&Route{}, &RouteList{})
}
117 changes: 117 additions & 0 deletions api/domain/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Domain")
os.Exit(1)
}
if err = (&domaincontroller.RouteReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("mailgun-controller"),
Config: config,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Route")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
45 changes: 45 additions & 0 deletions config/crd/bases/domain.mailgun.com_domains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,51 @@ spec:
external_dns:
description: Support for External-DNS
type: boolean
external_dns_records:
items:
description: Endpoint is a high-level way of a connection between
a service and an IP
properties:
dnsName:
description: The hostname of the DNS record
type: string
labels:
additionalProperties:
type: string
description: Labels stores labels defined for the Endpoint
type: object
providerSpecific:
description: ProviderSpecific stores provider specific config
items:
description: ProviderSpecificProperty holds the name and value
of a configuration which is specific to individual DNS providers
properties:
name:
type: string
value:
type: string
type: object
type: array
recordTTL:
description: TTL for the record
format: int64
type: integer
recordType:
description: RecordType type of record, e.g. CNAME, A, AAAA,
SRV, TXT etc
type: string
setIdentifier:
description: Identifier to distinguish multiple records with
the same name and type (e.g. Route53 records with routing
policies other than 'simple')
type: string
targets:
description: The targets the DNS record points to
items:
type: string
type: array
type: object
type: array
force_dkim_authority:
type: boolean
force_mx_check:
Expand Down
Loading

0 comments on commit 43c08a8

Please sign in to comment.