-
Notifications
You must be signed in to change notification settings - Fork 593
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
tweaks to get tests to work with private registry #1870
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ import ( | |
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc" | ||
) | ||
|
||
var TestPullSecretName = "kn-eventing-test-pull-secret" | ||
|
||
// ChannelTestRunner is used to run tests against channels. | ||
type ChannelTestRunner struct { | ||
ChannelFeatureMap map[string][]Feature | ||
|
@@ -133,6 +135,55 @@ func CreateNamespaceIfNeeded(t *testing.T, client *Client, namespace string) { | |
if err != nil { | ||
t.Fatalf("The default ServiceAccount was not created for the Namespace: %s", namespace) | ||
} | ||
|
||
// If the "default" Namespace has a secret called | ||
// "kn-eventing-test-pull-secret" then use that as the ImagePullSecret | ||
// on the "default" ServiceAccount in this new Namespace. | ||
// This is needed for cases where the images are in a private registry. | ||
|
||
// Get the Interfaces we need to access the resources in the cluster | ||
defSecI := client.Kube.Kube.CoreV1().Secrets("default") | ||
nsSAI := client.Kube.Kube.CoreV1().ServiceAccounts(namespace) | ||
nsSecI := client.Kube.Kube.CoreV1().Secrets(namespace) | ||
|
||
testSecret, _ := defSecI.Get(TestPullSecretName, metav1.GetOptions{}) | ||
|
||
// Check again. I've seen cases where it lies and if we need it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems odd, and is there a reason why you don't check the err returned? I'm not sure what you mean by "It" lies, are you saying above line returns nil, but the one below returns true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I mean that the apiserver will return nil+err even though the secret does exist. I can't explain why or how, but I ran into it often enough that I decided to just ask again to be sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vagababov Have you seen something like this before? Seems b0rk3n? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really. What is the actual error you're getting? If I were to guess you got either network problem error (connection refused, dial timeout) or overload error from API server. Which leads me to the main problem I see here: "never ignore errors". Also, I'd highly recommend to switch to informers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the err that's returned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me change the code to show the error (if I even get one) to see what's up.. But to add more intrigue, I've also seen cases like this.... I had this code:
Notice I would use the "name" from "testSecret", which should never be empty. Yet I would get this error:
I never saw this on my local testing, or IKS, only using Prow. |
||
// then the test will fail w/o it, so check again just to be sure. | ||
if testSecret == nil { | ||
testSecret, _ = defSecI.Get(TestPullSecretName, metav1.GetOptions{}) | ||
} | ||
|
||
if testSecret != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function seems similar in description, yet it's different and I'm trying to understand why? :) Can this be hoisted into a separate function and reused instead of having two versions of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are similar but different. This one only deals with the "default" SA and knows it can blindly copy the secret. Th other one deals with a new SA (so not "default") and needs to check to see if the secret already exists so it doesn't try to duplicate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They both have the check and re-check (which I must say is extremely worrying and seems extremely flaky and a bug in the k8s if that's the case). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverse the flow to be more go-style
|
||
// Found the secret, so now make a copy in our new namespace | ||
newSecret, err := nsSecI.Create( | ||
&corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: TestPullSecretName, | ||
}, | ||
Data: testSecret.Data, | ||
Type: testSecret.Type, | ||
}) | ||
if err != nil { | ||
t.Fatalf("TestSetup: Error copying the secret: %s", err) | ||
} | ||
|
||
// Now add it to the "default" ServiceAccount as a Pull Secret | ||
newSecretRef := corev1.LocalObjectReference{ | ||
Name: TestPullSecretName, | ||
} | ||
sa, err := nsSAI.Get("default", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatalf("TestSetup: Error getting ServiceAccount: %s", err) | ||
} | ||
|
||
sa.ImagePullSecrets = append(sa.ImagePullSecrets, newSecretRef) | ||
if _, err = nsSAI.Update(sa); err != nil { | ||
t.Fatalf("TestSetup: Error adding Secret to ServiceAccount: %s", err) | ||
} | ||
t.Logf("Copied ImagePullSecret(%s) into namespace: %s", | ||
newSecret.ObjectMeta.Name, namespace) | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed