Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deploy): separate -storage and -db pods #923

Merged
merged 28 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2606ae2
tmp
mwangggg Jun 4, 2024
67c708e
tmp
mwangggg Jun 5, 2024
509d862
tmp
mwangggg Jun 5, 2024
1815af8
separate db and storage into pods
mwangggg Jul 23, 2024
fbe1eef
tmp
mwangggg Jul 29, 2024
eb57ec8
readd core PVC
mwangggg Jul 29, 2024
f13ca56
tmp without tls
mwangggg Jul 30, 2024
c1581ea
tmp
mwangggg Jul 30, 2024
9163ac7
add db and storage certs
mwangggg Jul 31, 2024
b16facd
Merge branch 'main' into 814-separate-pods
andrewazores Nov 1, 2024
28efdea
comment out incomplete/incorrect db/storage tls configs
andrewazores Nov 1, 2024
d4c0035
remove authproxy uid override
andrewazores Nov 1, 2024
67cd857
cryostat expects to talk to storage over http only for now
andrewazores Nov 1, 2024
f19babf
correct envtests
andrewazores Nov 1, 2024
21d036c
remove authproxy uid from bundle
andrewazores Nov 5, 2024
bcd0a3e
fix(tls): use fixed-length cert CommonNames
andrewazores Nov 5, 2024
0d7173c
fixup! Merge branch 'tls-common-name' into 814-separate-pods
andrewazores Nov 5, 2024
4ce5cca
fix(tls): use fixed-length cert CommonNames (#968)
andrewazores Dec 20, 2024
29cd9a5
Merge branch 'main' into 814-separate-pods
andrewazores Dec 20, 2024
f424a67
refactor
andrewazores Jan 13, 2025
769fd5b
database cleanup
andrewazores Jan 13, 2025
071607f
make bundle
andrewazores Jan 13, 2025
add44dd
remove unused
andrewazores Jan 13, 2025
4717985
refactor
andrewazores Jan 13, 2025
6d341f2
rename
andrewazores Jan 13, 2025
ebe7895
nil-check
andrewazores Jan 13, 2025
7a9c415
format
andrewazores Jan 13, 2025
dbc788c
non-nil default value
andrewazores Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions internal/controllers/certmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cryostatio/cryostat-operator/internal/controllers/common"
resources "github.com/cryostatio/cryostat-operator/internal/controllers/common/resource_definitions"
"github.com/cryostatio/cryostat-operator/internal/controllers/model"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -414,25 +415,43 @@ func (r *Reconciler) reconcileAgentCertificate(ctx context.Context, cert *certv1
return nil
}

var errCertificateModified error = errors.New("certificate has been modified")

func (r *Reconciler) createOrUpdateCertificate(ctx context.Context, cert *certv1.Certificate, owner metav1.Object) error {
certSpec := cert.Spec.DeepCopy()
certCopy := cert.DeepCopy()
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, cert, func() error {
if owner != nil {
if err := controllerutil.SetControllerReference(owner, cert, r.Scheme); err != nil {
return err
}
}
// Update Certificate spec
cert.Spec = *certSpec

if cert.CreationTimestamp.IsZero() {
cert.Spec = certCopy.Spec
} else if !cmp.Equal(cert.Spec, certCopy.Spec) {
return errCertificateModified
}

return nil
})
if err != nil {
if err == errCertificateModified {
return r.recreateCertificate(ctx, certCopy, owner)
}
return err
}
r.Log.Info(fmt.Sprintf("Certificate %s", op), "name", cert.Name, "namespace", cert.Namespace)
return nil
}

func (r *Reconciler) recreateCertificate(ctx context.Context, cert *certv1.Certificate, owner metav1.Object) error {
err := r.deleteCertWithSecret(ctx, cert)
if err != nil {
return err
}
return r.createOrUpdateCertificate(ctx, cert, owner)
}

func newKeystoreSecret(cr *model.CryostatInstance) *corev1.Secret {
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down
60 changes: 60 additions & 0 deletions internal/controllers/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,66 @@ func (c *controllerTest) commonTests() {
t.expectCertificates()
})
})
Context("with modified certificates", func() {
var oldCerts []*certv1.Certificate
BeforeEach(func() {
t.objs = append(t.objs, t.NewCryostat().Object, t.OtherCAIssuer())
oldCerts = []*certv1.Certificate{
t.OtherCACert(),
t.OtherAgentProxyCert(),
t.OtherCryostatCert(),
t.OtherReportsCert(),
}
// Add an annotation for each cert, the test will assert that
// the annotation is gone.
for i, cert := range oldCerts {
metav1.SetMetaDataAnnotation(&oldCerts[i].ObjectMeta, "bad", "cert")
t.objs = append(t.objs, cert)
}
})
JustBeforeEach(func() {
cr := t.getCryostatInstance()
for _, cert := range oldCerts {
// Make the old certs owned by the Cryostat CR
err := controllerutil.SetControllerReference(cr.Object, cert, t.Client.Scheme())
Expect(err).ToNot(HaveOccurred())
err = t.Client.Update(context.Background(), cert)
Expect(err).ToNot(HaveOccurred())
}
t.reconcileCryostatFully()
})
It("should recreate certificates", func() {
t.expectCertificates()
})
})
Context("with a modified certificate TLS CommonName", func() {
var oldCerts []*certv1.Certificate
BeforeEach(func() {
oldCerts = []*certv1.Certificate{
t.NewCryostatCert(),
t.NewReportsCert(),
t.NewAgentProxyCert(),
}
t.objs = append(t.objs, t.NewCryostat().Object, t.OtherCAIssuer())
for _, cert := range oldCerts {
t.objs = append(t.objs, cert)
}
})
JustBeforeEach(func() {
cr := t.getCryostatInstance()
for _, cert := range oldCerts {
// Make the old certs owned by the Cryostat CR
err := controllerutil.SetControllerReference(cr.Object, cert, t.Client.Scheme())
Expect(err).ToNot(HaveOccurred())
err = t.Client.Update(context.Background(), cert)
Expect(err).ToNot(HaveOccurred())
}
t.reconcileCryostatFully()
})
It("should recreate certificates", func() {
t.expectCertificates()
})
})

Context("reconciling a multi-namespace request", func() {
targetNamespaces := []string{"multi-test-one", "multi-test-two"}
Expand Down
25 changes: 25 additions & 0 deletions internal/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,12 @@ func (r *TestResources) NewCryostatCert() *certv1.Certificate {
}
}

func (r *TestResources) OtherCryostatCert() *certv1.Certificate {
cert := r.NewCryostatCert()
cert.Spec.CommonName = fmt.Sprintf("%s.%s.svc", r.Name, r.Namespace)
return cert
}

func (r *TestResources) NewReportsCert() *certv1.Certificate {
return &certv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1284,6 +1290,12 @@ func (r *TestResources) NewDatabaseCert() *certv1.Certificate {
}
}

func (r *TestResources) OtherReportsCert() *certv1.Certificate {
cert := r.NewReportsCert()
cert.Spec.CommonName = fmt.Sprintf("%s-reports.%s.svc", r.Name, r.Namespace)
return cert
}

func (r *TestResources) NewAgentProxyCert() *certv1.Certificate {
return &certv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1336,6 +1348,12 @@ func (r *TestResources) NewStorageCert() *certv1.Certificate {
}
}

func (r *TestResources) OtherAgentProxyCert() *certv1.Certificate {
cert := r.NewAgentProxyCert()
cert.Spec.CommonName = fmt.Sprintf("%s-agent.%s.svc", r.Name, r.Namespace)
return cert
}

func (r *TestResources) NewCACert() *certv1.Certificate {
return &certv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1353,6 +1371,13 @@ func (r *TestResources) NewCACert() *certv1.Certificate {
}
}

func (r *TestResources) OtherCACert() *certv1.Certificate {
cert := r.NewCACert()
cert.Spec.CommonName = fmt.Sprintf("ca.%s.cert-manager", r.Name)
cert.Spec.SecretName = r.Name + "-ca"
return cert
}

func (r *TestResources) NewAgentCert(namespace string) *certv1.Certificate {
name := r.getClusterUniqueNameForAgent(namespace)
return &certv1.Certificate{
Expand Down
Loading