Skip to content
Snippets Groups Projects
Unverified Commit c0443a7e authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub
Browse files

Merge pull request #8191 from adrianmoisey/enable-flakey-tests

Enable TestUnchangedCAReloader tests
parents 2511e448 8d90da9a
Branches
Tags
No related merge requests found
...@@ -276,120 +276,119 @@ func TestChangedCAReloader(t *testing.T) { ...@@ -276,120 +276,119 @@ func TestChangedCAReloader(t *testing.T) {
assert.NotEqual(t, oldCAEncodedString, newCAEncodedString, "expected CA to change") assert.NotEqual(t, oldCAEncodedString, newCAEncodedString, "expected CA to change")
} }
// TODO(omerap12): Temporary workaround for flakiness (#7831) func TestUnchangedCAReloader(t *testing.T) {
// func TestUnchangedCAReloader(t *testing.T) { tempDir := t.TempDir()
// tempDir := t.TempDir() caCert := &x509.Certificate{
// caCert := &x509.Certificate{ SerialNumber: big.NewInt(0),
// SerialNumber: big.NewInt(0), Subject: pkix.Name{
// Subject: pkix.Name{ Organization: []string{"ca"},
// Organization: []string{"ca"}, },
// }, NotBefore: time.Now(),
// NotBefore: time.Now(), NotAfter: time.Now().AddDate(2, 0, 0),
// NotAfter: time.Now().AddDate(2, 0, 0), IsCA: true,
// IsCA: true, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
// ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
// KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, BasicConstraintsValid: true,
// BasicConstraintsValid: true, }
// } caKey, err := rsa.GenerateKey(rand.Reader, 4096)
// caKey, err := rsa.GenerateKey(rand.Reader, 4096) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// } caBytes, err := x509.CreateCertificate(rand.Reader, caCert, caCert, &caKey.PublicKey, caKey)
// caBytes, err := x509.CreateCertificate(rand.Reader, caCert, caCert, &caKey.PublicKey, caKey) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// } caPath := path.Join(tempDir, "ca.crt")
// caPath := path.Join(tempDir, "ca.crt") caFile, err := os.Create(caPath)
// caFile, err := os.Create(caPath) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// } err = pem.Encode(caFile, &pem.Block{
// err = pem.Encode(caFile, &pem.Block{ Type: "CERTIFICATE",
// Type: "CERTIFICATE", Bytes: caBytes,
// Bytes: caBytes, })
// }) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// }
testClientSet := fake.NewSimpleClientset()
// testClientSet := fake.NewSimpleClientset()
selfRegistration(
// selfRegistration( testClientSet,
// testClientSet, readFile(caPath),
// readFile(caPath), 0*time.Second,
// 0*time.Second, "default",
// "default", "vpa-service",
// "vpa-service", "http://example.com/",
// "http://example.com/", true,
// true, int32(32),
// int32(32), "",
// "", []string{},
// []string{}, false,
// false, "key1:value1,key2:value2",
// "key1:value1,key2:value2", )
// )
webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations()
// webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations() oldWebhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{})
// oldWebhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// }
assert.Len(t, oldWebhookConfig.Webhooks, 1, "expected one webhook configuration")
// assert.Len(t, oldWebhookConfig.Webhooks, 1, "expected one webhook configuration") webhook := oldWebhookConfig.Webhooks[0]
// webhook := oldWebhookConfig.Webhooks[0] oldWebhookCABundle := webhook.ClientConfig.CABundle
// oldWebhookCABundle := webhook.ClientConfig.CABundle
var reloadWebhookCACalled, patchCalled atomic.Bool
// var reloadWebhookCACalled, patchCalled atomic.Bool reloadWebhookCACalled.Store(false)
// reloadWebhookCACalled.Store(false) patchCalled.Store(false)
// patchCalled.Store(false) testClientSet.PrependReactor("get", "mutatingwebhookconfigurations", func(action k8stesting.Action) (bool, runtime.Object, error) {
// testClientSet.PrependReactor("get", "mutatingwebhookconfigurations", func(action k8stesting.Action) (bool, runtime.Object, error) { reloadWebhookCACalled.Store(true)
// reloadWebhookCACalled.Store(true) return false, nil, nil
// return false, nil, nil })
// }) testClientSet.PrependReactor("patch", "mutatingwebhookconfigurations", func(action k8stesting.Action) (bool, runtime.Object, error) {
// testClientSet.PrependReactor("patch", "mutatingwebhookconfigurations", func(action k8stesting.Action) (bool, runtime.Object, error) { patchCalled.Store(true)
// patchCalled.Store(true) return false, nil, nil
// return false, nil, nil })
// })
reloader := certReloader{
// reloader := certReloader{ clientCaPath: caPath,
// clientCaPath: caPath, mutatingWebhookClient: testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations(),
// mutatingWebhookClient: testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations(), }
// } stop := make(chan struct{})
// stop := make(chan struct{}) defer close(stop)
// defer close(stop) if err := reloader.start(stop); err != nil {
// if err := reloader.start(stop); err != nil { t.Error(err)
// t.Error(err) }
// }
originalCaFile, err := os.ReadFile(caPath)
// originalCaFile, err := os.ReadFile(caPath) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// } err = os.WriteFile(caPath, originalCaFile, 0666)
// err = os.WriteFile(caPath, originalCaFile, 0666) if err != nil {
// if err != nil { t.Error(err)
// t.Error(err) }
// }
oldCAEncodedString := base64.StdEncoding.EncodeToString(oldWebhookCABundle)
// oldCAEncodedString := base64.StdEncoding.EncodeToString(oldWebhookCABundle)
for tries := 0; tries < 10; tries++ {
// for tries := 0; tries < 10; tries++ { if reloadWebhookCACalled.Load() {
// if reloadWebhookCACalled.Load() { break
// break }
// } time.Sleep(1 * time.Second)
// time.Sleep(1 * time.Second) }
// } if !reloadWebhookCACalled.Load() {
// if !reloadWebhookCACalled.Load() { t.Error("expected reloadWebhookCA to be called")
// t.Error("expected reloadWebhookCA to be called") }
// }
assert.False(t, patchCalled.Load(), "expected patch to not be called")
// assert.False(t, patchCalled.Load(), "expected patch to not be called")
newWebhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{})
// newWebhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) assert.Nil(t, err, "expected no error")
// assert.Nil(t, err, "expected no error") assert.NotNil(t, newWebhookConfig, "expected webhook configuration")
// assert.NotNil(t, newWebhookConfig, "expected webhook configuration") assert.Len(t, newWebhookConfig.Webhooks, 1, "expected one webhook configuration")
// assert.Len(t, newWebhookConfig.Webhooks, 1, "expected one webhook configuration")
newWebhookCABundle := newWebhookConfig.Webhooks[0].ClientConfig.CABundle
// newWebhookCABundle := newWebhookConfig.Webhooks[0].ClientConfig.CABundle newCAEncodedString := base64.StdEncoding.EncodeToString(newWebhookCABundle)
// newCAEncodedString := base64.StdEncoding.EncodeToString(newWebhookCABundle) assert.Equal(t, oldCAEncodedString, newCAEncodedString, "expected CA to not change")
// assert.Equal(t, oldCAEncodedString, newCAEncodedString, "expected CA to not change") }
// }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment