Skip to content
Snippets Groups Projects
Commit 81d27d48 authored by Omer Aplatony's avatar Omer Aplatony
Browse files

comment out TestUnchangedCAReloader test (flake)

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