Repository navigation
Conversation
|
@W-OK-E Thanks for the PR! I will review it tomorrow. |
Saadmrp1038
left a comment
There was a problem hiding this comment.
@W-OK-E This currently only works on kind since it uses docker exec for node-level changes and the Docker bridge for networking. You will need to implement logic for real-cluster path. If possible can you explore an implementation where the kind vs real cluster difference is minimal? Most of the logic should be shareable, just the node access method differs.
|
Sure! On it. |
|
Hello @Saadmrp1038 ! For the actual cluster implementation, I went on with aws EC2 instances and kept running into a issue regardless of what problem is launched at hand: During the application deployment ( For which, I added def _repair_calico_crds(self):
"""Re-apply the Calico manifest if calico-kube-controllers' required CRDs are
missing. No-op on clusters not running manifest-based Calico (e.g. kind /
kindnet), and idempotent when the CRDs are already present."""
deploy = self.kubectl.exec_command(
"kubectl get deploy -n kube-system calico-kube-controllers --ignore-not-found -o name"
)
if "calico-kube-controllers" not in (deploy or ""):
return # not a Calico cluster -- nothing to repair
missing = [
crd
for crd in self._CALICO_REQUIRED_CRDS
if crd
not in (self.kubectl.exec_command(f"kubectl get crd {crd} --ignore-not-found -o name") or "")
]
if not missing:
return
self.logger.warning(
f"Calico CRDs missing {missing}; re-applying Calico manifest to recover calico-kube-controllers"
)
self.kubectl.exec_command(f"kubectl apply -f {self._CALICO_MANIFEST_URL}")
# Force a fresh pod so it picks up the recreated CRDs immediately instead of
# waiting out its CrashLoopBackOff backoff (which can be minutes).
self.kubectl.exec_command(
"kubectl delete pod -n kube-system -l k8s-app=calico-kube-controllers --ignore-not-found"
)Have you faced this issue before, or could this be due to my specific choice of aws as a cluster? PS - The code has not been committed yet to this PR so if you think I should report it elsewhere, let me know! |
|
@W-OK-E Hmmm. I didn't face it before. Might be somehow related to using EC2s. When you ran the ansible setup script was there any error during Calico installation? |
|
Hey @Saadmrp1038 , apologies for the delayed response, since I did not recall there being an explicit issue with calico installation, I went on to reproduce the error on 5 different sets of AWS clusters and managed to get some sort of an explanation. A few differences between my AWS and your cloudlab setup maybe worth highlighting here:
On every new cluster, when My hypothesis currently is that on my AWS clusters, that re-apply burst pushes etcd hard enough that two specific CRDs ( I think the root-cause is the environment my ported playbook runs in. CloudLab nodes use local SSD/NVMe disk; the AWS nodes run etcd on EBS (network-attached storage), which has much higher and What I have tested / ruled out on 5 separate AWS Clusters:
Current Patch in my fork:
Please let me know if you have any questions/suggestions on my analysis. |
|
@W-OK-E Thanks for the detailed testing! This scenerio is really unexpected :) |
|
No worries @Saadmrp1038 !! |
|
Hey @Saadmrp1038 ! I tested the problem on kind as well as AWS clusters and have pushed the changes, feel free to comment or suggest changes. Summary of what was done:
However, I sort of feel that the explanation for why the two Calico CRDs lose the apiserver discovery-resync race on AWS but not CloudLab is flaky; the swapped kernel is another possible clue. I will spin up a few instances from other cloud providers maybe and see if it's the same there. P.S. - I tried testing Straus on this problem but hit rate limit after the first few API calls :( Please let me know if and when you do test an agent on this and how it goes. |
Saadmrp1038
left a comment
There was a problem hiding this comment.
@W-OK-E the real cluster code is working well! Left some comments below.
However, I sort of feel that the explanation for why the two Calico CRDs lose the apiserver discovery-resync race on AWS but not CloudLab is flaky
I will also test on AWS to see what's wrong. The deployment code might need to be more defensive to account for these weird unexpected behaviours.
I tried testing Straus on this problem but hit rate limit after the first few API calls :( Please let me know if and when you do test an agent on this and how it goes.
Sure! I will do a set of agent runs after the oracle fix. That's the main blocker right now to doing the runs.
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ImagePullSecretMitigationOracle(Oracle): |
There was a problem hiding this comment.
We should add importance = 1.0 class attribute. Not really needed here. Just to keep consistent with other oracles.
There was a problem hiding this comment.
Patched, will be pushed.
There was a problem hiding this comment.
@W-OK-E I think this is still missing (again it does not really matter here just for consistency).
There was a problem hiding this comment.
This one is still missing :) Could you add importance = 1.0 here for consistency?
| apps_v1 = client.AppsV1Api() | ||
|
|
||
| # Check 1: imagePullSecret must exist | ||
| try: |
There was a problem hiding this comment.
This feels too strict. The oracle requires a secret named exactly hotel-registry-creds and requires the Deployment to reference it. An agent could provide valid credentials via a differently-named secret or via the default ServiceAccount's imagePullSecrets. The pod would be Running but the oracle rejects it.
There was a problem hiding this comment.
The "default ServiceAccount imagePullSecrets" path does not work standalone for this fault (detailed below). However, the oracle has been relaxed and does not demand strict names equality for secrets and registries.
There was a problem hiding this comment.
@W-OK-E I see. I am guessing deployment patch + SA would've worked then (?). Although at that point you would have to ask what the agent is even doing XD
|
Hey @Saadmrp1038 !! As requested, the required changes were made and verified to run both on kind and real clusters.
The following tests were done:
There's a finding too here, on your point earlier:
The "default ServiceAccount imagePullSecrets" path does not work standalone for this fault. The fault pins Let me know if I missed something here or if more changes are required. |
|
@W-OK-E Nice work! I am testing again. A nit. Let's change all labels that have |
Saadmrp1038
left a comment
There was a problem hiding this comment.
@W-OK-E when the image is already cached on the nodes from previous runs we should be able to directly push it to the private registry instead of pulling from Docker Hub. That would be way faster. Can you please test it out?
Saadmrp1038
left a comment
There was a problem hiding this comment.
@W-OK-E I ran some agent tests. The sregym.io/fault-active, sregym.io/original-image and sregym.io/original-image-pull-policy annotations on the deployment are giving the agent the answer. It reads the labels and understands that it's an intentional fault injection and can also understand what was injected. It reverts the fault with kubectl patch by changing the image ref to the public one and the image policy to IfNotPresent. The public image is still cached on the node so IfNotPresent means no pull happens and the Docker Hub block never triggers. The app becomes healthy and the agent submits.
Oracle does catch it (anti-cheat works), but the agent thinks it solved the problem.
Two things should be done:
- The annotations shouldn't contain
sregymor expose the fault details directly. - Clean up the cached public image from nodes during injection so that the public ref actually breaks.
|
@Saadmrp1038 I have a slightly different plan in mind, which stems from my current analysis:
Let me know what path seems the most feasible to you! |
|
@W-OK-E I gave it some thought. Your points are valid. It slipped my mind that |
|
Hey @Saadmrp1038 ! I have implemented the problem in What Changed
What I have tested
|
|
Also, I am aware that the current changes are extremely bulky with docstrings and comments, but they just address some of the points that we have discussed in this PR. Besides any other changes, I will clean them up too once you give a go @Saadmrp1038. |
| Helm.assert_if_deployed(self.helm_configs["namespace"]) | ||
|
|
||
|
|
||
| class MissingImagePullSecretAstronomyShop(Problem): |
There was a problem hiding this comment.
I’m not sure we need this problem for both Astronomy Shop and Blueprint Hotel Reservation. The failure and expected diagnosis are basically the same, and most of the implementation is duplicated between the two files.
Since Blueprint is much lighter and already gives us a different image for each service, I would prefer keeping the Blueprint version and dropping the Astronomy version. Is there a specific benchmark reason why we need both?
There was a problem hiding this comment.
Ahh yes!
You are right. It's just that the blueprint application can run quicker and on low-end systems since I had some issues getting Astronomy shop and other applications running.
We can choose to not include the astronomy-shop implementation.
| self.core_v1.create_namespaced_secret(namespace=self.namespace, body=secret) | ||
| except client.exceptions.ApiException as e: | ||
| if e.status == 409: | ||
| self.core_v1.replace_namespaced_secret(name=_SECRET_NAME, namespace=self.namespace, body=secret) |
There was a problem hiding this comment.
I think recovery will fail if the agent has already recreated geo-service-registry-creds, which is also the fix we expect it to make.
create_namespaced_secret() will return 409, but this new Secret object does not have the existing resourceVersion, so the replace request will also fail. Could we read the existing Secret and copy its resourceVersion, or patch it instead? It would also be good to test recovery after the agent has recreated the Secret.
There was a problem hiding this comment.
I will check and make the changes.
|
@munimthahmid : @W-OK-E informed us earlier that he may not have time to continue working on the problem. Are you trying to take the problem over and merge it? (that will be great!) If you are purely doing the review and expect @W-OK-E to revise it PR, it may not happen. |
Hey @tianyin, I can review and refine the PR over the weekends, that would be totally fine for me! |
|
Orz |
| config.load_kube_config() | ||
|
|
||
| @staticmethod | ||
| def cleanup_leftovers() -> None: |
There was a problem hiding this comment.
I’m a little worried about this cleanup because fix_kubernetes() runs it on every conductor startup.
It removes all certs.d/*:5000 entries and the full docker.io and ghcr.io directories. The cri-dockerd path also replaces the complete daemon.json. If the cluster already has a registry mirror or another insecure registry configured, we will remove that unrelated configuration.
Could we save the original node configuration before changing it and restore that exact state during cleanup?
There was a problem hiding this comment.
There were a bunch of alternatives here, however most would break other problem statements at startup. However, your concern is valid, I will recheck and see if there is a workaround or try your suggested pathway.
|
|
||
| # Primary criterion: the target workload's pods must be Running + Ready with | ||
| # no image-pull failure. Accepts ANY working credential mechanism. | ||
| pods = v1.list_namespaced_pod( |
There was a problem hiding this comment.
I think the oracle can be bypassed here because it selects pods only by label, without checking whether they belong to the target Deployment.
For example, the target Deployment could be scaled to zero and replaced with a separate healthy pod using the same label. The oracle would still pass even though the actual workload is disabled.
Could we also check that the Deployment has at least one replica, its rollout is ready, and the pods belong to its ReplicaSet?
| if observed_current and updated == desired and total == desired and ready == desired: | ||
| return | ||
| time.sleep(3) | ||
| logger.warning("Deployment '%s' rollout not complete after %ds", deployment_name, timeout) |
There was a problem hiding this comment.
_wait_for_deployment_ready() only logs a warning when it times out, so injection continues even if the private registry and valid Secret never produced a healthy pod.
In that case, the benchmark may be testing a registry setup failure instead of the deleted image pull Secret. I think this baseline check should raise on timeout rather than continuing.
|
@W-OK-E Thanks for your patience, and sorry it took me so long to get back to this. I’ve left a few inline comments. Please let me know once you’ve addressed them, and I’ll take another look. |
|
@W-OK-E, let me know if you still intend to work on the fixes, otherwise, I think I will fix the remaining issues and merge the PR if it's good enough |
Hey @munimthahmid ! Yes I am working on it right now. I apologize for the delay, just got a bit busy with the internship workload, changes will be pushed in a day or two. |
|
I'm closing inactive PRs that are more than 2 months. Feel free to reopen if you are still working on it. |
Add Problem: Missing ImagePullSecret (Hotel Reservation)
This PR is based on the discussion in #852. Grateful to @Saadmrp1038 for all the suggestions and answering my questions. Happy to make any other changes if required. Description follows.
Summary
MissingImagePullSecretHotelReservation— a new SREGym fault-injection problemwhere an agent must diagnose and fix a pod stuck in
ImagePullBackOffdue to adeleted imagePullSecret.
ImagePullSecretMitigationOracleto evaluate whether the agent's fix is correct.Changed files
sregym/conductor/problems/missing_image_pull_secret_hotel_reservation.pysregym/conductor/oracles/image_pull_secret_mitigation.pysregym/conductor/problems/registry.pysregym/conductor/conductor.pyfix_kubernetes()How fault injection works
Infrastructure setup (
inject_fault)The problem creates a realistic private-registry scenario before injecting the fault:
Private registry — starts
sregym-private-registry(Dockerregistry:2withhtpasswd/bcrypt auth) on the Kind Docker bridge network. Configures containerd on
every Kind node to accept HTTP pulls from it (
/etc/containerd/certs.d/<ip>:5000/).Image relocation — pulls the existing
hotel-reservationimage from thein-cluster containerd store, re-tags and pushes it into the private registry via
the host-mapped port (
localhost:5001). Repoints therecommendationDeploymentto pull from
<registry-ip>:5000/hotel-reservation:latestwithimagePullPolicy: Always.Valid secret first — creates
hotel-registry-creds(akubernetes.io/dockerconfigjsonsecret) and verifies the pod comes up healthy. This confirms the full plumbing works
before any fault is injected.
Discovery breadcrumbs — creates a separate
infra-registrynamespace containing:private-registry-creds-mastersecret (a copy of the valid credentials)registry-access-runbookConfigMap linking to the master secretAn agent following events/logs naturally finds
FailedToRetrieveImagePullSecret,then the runbook, then the master secret, then recreates the missing per-namespace
secret. This mirrors the real-world on-call pattern.
Docker Hub block — starts
sregym-dockerhub-block(nginx returning 403) on theKind bridge network with DNS alias
dockerhub-mirror.internal. Configures containerdon every Kind node to use this as a mirror for
docker.io(
/etc/containerd/certs.d/docker.io/hosts.toml). This prevents an agent frombypassing the secret by simply repointing the image to a public registry.
The fault — deletes
hotel-registry-creds. Forces a pod restart. The podimmediately enters
ImagePullBackOff.Decoy pods — creates two pods that emit
FailedToRetrieveImagePullSecretwarningevents but stay
Running(they reference the decoy secretnonexistent-pull-creds,which doesn't exist, but their image is cached so the pull succeeds). An agent must
correlate the warning event with actual pod phase to identify the one genuinely broken
workload.
What the agent is expected to do
The agent observes
recommendationinImagePullBackOff, investigates the events(
FailedToRetrieveImagePullSecretforhotel-registry-creds), navigates thediscovery path (
registry-access-runbookConfigMap →infra-registrynamespace →private-registry-creds-master), and recreates the missing secret in the applicationnamespace with the correct credentials. The pod should return to
Running.The decoy pods are a distractor: the agent must not be misled by other pods emitting
the same warning event into patching the wrong workload or concluding the problem is
already resolved.
Recovery (
recover_fault)Restores the Deployment to its original public image and
imagePullPolicy, removesthe private registry, removes the containerd mirror configs from all Kind nodes,
removes the
infra-registrynamespace, and deletes the decoy pods.Mitigation oracle (
ImagePullSecretMitigationOracle)Evaluates whether the agent's fix is complete. Checks in order:
hotel-registry-credssecret exists in the application namespace..dockerconfigjsonwith a non-emptyauthskey.recommendationDeployment references the secret inspec.template.spec.imagePullSecrets.recommendationpods areRunningand every container isReady.Additional changes: containerd docker.io redirect survives Ctrl+C
The Docker Hub block writes
/etc/containerd/certs.d/docker.io/hosts.tomlon eachKind node — a node-filesystem file with no corresponding Kubernetes object. Namespace
teardown and app undeploy do not touch it. If the conductor is killed (Ctrl+C) before
recover_faultruns, the redirect persists on the next startup and breaks ALL publicimage pulls cluster-wide (e.g.
wrk2-jobentersImagePullBackOffimmediately,completely unrelated to the intended fault).
Fix: four teardown methods (
_stop_registry,_get_kind_nodes,_remove_containerd_dockerhub_block,_stop_dockerhub_block) were converted to@staticmethods. A newcleanup_leftovers()staticmethod composes them. This iscalled from
Conductor.fix_kubernetes()at every startup, unconditionally, followingthe existing pattern used by
PodCIDRExhaustionHotelReservation,KubeletEvictionThresholdMisconfig, and others. All operations are idempotent.Testing
inject_fault→ pod entersImagePullBackOff→ agent recreatessecret →
mitigation_oraclepasses →recover_fault→ cluster restored cleanly.recover_fault,inject_faultsucceeds again withoutresidual state.
recover_fault→ restart conductor →
fix_kubernetes()logs[FIX] MissingImagePullSecret containerd dockerhub-block leftover if any→containerd
docker.ioconfig removed from all nodes →wrk2-joband all other podscome up
Running→ only the target pod entersImagePullBackOffafter re-injection.FailedToRetrieveImagePullSecret; onlyrecommendationis actually stuck. The two decoys areRunning/Ready.