Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
autoscaler
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
kubernetes
autoscaler
Commits
c0443a7e
Unverified
Commit
c0443a7e
authored
3 months ago
by
Kubernetes Prow Robot
Committed by
GitHub
3 months ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #8191 from adrianmoisey/enable-flakey-tests
Enable TestUnchangedCAReloader tests
parents
2511e448
8d90da9a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
vertical-pod-autoscaler/pkg/admission-controller/certs_test.go
+116
-117
116 additions, 117 deletions
...cal-pod-autoscaler/pkg/admission-controller/certs_test.go
with
116 additions
and
117 deletions
vertical-pod-autoscaler/pkg/admission-controller/certs_test.go
+
116
−
117
View file @
c0443a7e
...
@@ -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")
}
// }
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment