How to propagate a Kubernetes operator error to kubectl command line? - go

I have a Kubernetes operator that creates a new Deployment based upon the custom resource configuration. There are some error conditions that will cause a failure and the Deployment creation step is skipped. Is it possible to have the error text displayed on the command line?
At the moment I have:
err := validateSettings()
if err != nil {
// Log the error
logger.Error(err, "The Deployment settings are invalid")
// I also record the event in the custom object
r.recorder.Event(object, "Warning", "Failed", err.Error())
return reconcile.Result{}, err
}
When a user creates the custom object, the deployment is not created but the command line says that the custom object was created successfully.
# kubectl apply -f myobject.yaml
test.com/my-object created
The logs for the operator show the error and the a describe of the custom object show the event. I was hoping to have the event text displayed after the kubectl apply command.

Related

AWS ECS WaitUntilTasksRunningWithContext returning ResourceNotReady

I'm not very proficient with Go but seeing the following error while waiting for an ECS task to start:
error waiting AWS ECS Task "arn:aws:ecs:eu-west-1:123456789012:task/ecs-cluster/22452be490a149e781a596a7847dd27c" to be in "Running" state: ResourceNotReady: failed waiting for successful resource state
The task being started has a launch type of EC2. Sometimes it will start, but fairly regularly it will return that error.
We get that while doing:
input := ecs.DescribeTasksInput{
Cluster: &cluster,
Tasks: []*string{&taskARN},
}
err = a.ecsSvc.WaitUntilTasksRunningWithContext(ctx, &input)
if err != nil {
return fmt.Errorf(`error waiting AWS Fargate Task %q to be in "Running" state: %w`, taskARN, err)
}
What would be the better solution here? To send in a custom WaiterOption to WaitUntilTasksRunningWithContext or to rather just retry the method if we get this failure?
For additional context. When checking in the console, I can see the task running, so this is most probably a case of WaitUntilTasksRunningWithContext returning too quickly.
If a retry is a good option, how would that look like?

Cannot delete custom resource definition which is from previous installation effect to new installations

Previously created crds won't delete. still in the terminate state. any solution to delete this crds properly?
Error from server (MethodNotAllowed): error when creating "elkkib.yml": create not allowed while custom resource definition is terminating
Error from server (MethodNotAllowed): error when creating "elkkib.yml": create not allowed while custom resource definition is terminating
Try this command:
kubectl patch crd/{your crd name} -p '{"metadata":{"finalizers":[]}}' --type=merge
Refer to this:https://github.com/kubernetes/kubernetes/issues/60538

TeamCity: Customize build failed error message (include it in email)

We are using TeamCity to process hundreds of builds. We added a custom command line script which prints an error to console, and if the enviroment variable TEAMCITY_VERSION is set, then we print the error message in the format TeamCity understands:
Console.Out.WriteLine(
"##teamcity[message text='Custom Script failed.' errorDetails='" +
ex.Message + "' status='ERROR']");
Now, I see that the error is displayed in the build log, however, under the build details, we only see [13:00:25]Process exited with code 1, and in the email notification sent to developers that included changes in that build, only that line is sent.
Is it possible to send in the email, and include in the build details the error we actually print to the console?
There is some build script interaction available:
Console.Out.WriteLine(
"##teamcity[buildProblem text='Custom Script failed.' errorDetails='" +
ex.Message + "']");
And complete it with a buildStatus:
Console.Out.WriteLine(
"##teamcity[buildStatus text='{build.status.text} : Environment variable issue.' status='FAILURE']");
You can get more information about building script interaction on the official website:
When you will send the mail, if you have a specific routine which watch the build, you can get information easily using the available api.

update existing infrastructure on heroku using terraform

I've got this infrastructure description
variable "HEROKU_API_KEY" {}
provider "heroku" {
email = "sebastrident#gmail.com"
api_key = "${var.HEROKU_API_KEY}"
}
resource "heroku_app" "default" {
name = "judge-re"
region = "us"
}
Originally I forgot to specify buildpack. It created the application on heroku. I decided to add it to resource entry
buildpacks = [
"heroku/java"
]
But when I try to apply the plan in terraform I get this error
Error: Error applying plan:
1 error(s) occurred:
* heroku_app.default: 1 error(s) occurred:
* heroku_app.default: Post https://api.heroku.com/apps: Name is already taken
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
Terraform plan looks like this
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ heroku_app.judge_re
id: <computed>
all_config_vars.%: <computed>
buildpacks.#: "1"
buildpacks.0: "heroku/java"
config_vars.#: <computed>
git_url: <computed>
heroku_hostname: <computed>
name: "judge-re"
region: "us"
stack: <computed>
web_url: <computed>
Plan: 1 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
As a workaround I tried to add destroy in my deploy.sh script
terraform init
terraform plan
terraform destroy -force
terraform apply -auto-approve
But it does not destroy the resource as I get the message Destroy complete! Resources: 0 destroyed.
What is the problem?
Link to build
It looks like you also changed the name of the resource. Your original example has the resource name heroku_app.default while your plan has heroku_app.judge_re.
To point your state to the remote resource, so Terraform knows you are editing and not trying to recreate the resource, use terraform import:
terraform import heroku_app.judge_re judge-re
In terraform, normally you needn't destroy the whole stack, which you just want to re-build one or several resources in it.
terraform taint does this trick. The terraform taint command manually marks a Terraform-managed resource as tainted, forcing it to be destroyed and recreated on the next apply.
terraform taint heroku_app.default
Second, when you troubleshooting why the resource isn't list in destroy resource, please make sure you point to the right terraform tfstate file.
when you run terraform plan, did you see any resources which already was created?

what "unknown tls.Config field" Error Means?

While I compile a go language code using "go install", I got the following error:
./xyzcheck.go:34: unknown tls.Config field 'EarlyCCS' in struct literal
here is the code that make that error
conn, err = tls.Dial("tcp", target, &tls.Config{InsecureSkipVerify: true, EarlyCCS: 2})
if err == nil {
fmt.Printf("\x1b[31mXYZ Check is OK.\x1b[0m\n")
os.Exit(1)
}
I googled this error but no luck.
If anyone can tell me what is the reason for this error? and how can I fix it. it will be great.
Thanks
ABC: 2 is not a valid parameter for config. There is documentation on config settings for tls here: http://golang.org/pkg/crypto/tls/#Config
The author has a patch that needs to be applied to the tls package. This was clearly explained on his blog page where you obtained this script.
Apply the patch to the tls package, re-run the script and it will work.

Resources