This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
terraform: controller timeout, cleanup the last error and fix returne…
…d refresh result in ongoing state Signed-off-by: Muvaffak Onus <me@muvaf.com>
- Loading branch information
Showing
11 changed files
with
220 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2021 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package resource | ||
|
||
import ( | ||
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
tferrors "github.com/crossplane-contrib/terrajet/pkg/terraform/errors" | ||
) | ||
|
||
// Condition constants. | ||
const ( | ||
TypeAsyncOperation = "AsyncOperation" | ||
|
||
ReasonApplyFailure xpv1.ConditionReason = "ApplyFailure" | ||
ReasonDestroyFailure xpv1.ConditionReason = "DestroyFailure" | ||
ReasonSuccess xpv1.ConditionReason = "Success" | ||
) | ||
|
||
// LastOperationCondition returns the condition depending on the content | ||
// of the error. | ||
func LastOperationCondition(err error) xpv1.Condition { | ||
switch { | ||
case err == nil: | ||
return xpv1.Condition{ | ||
Type: TypeAsyncOperation, | ||
Status: corev1.ConditionTrue, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: ReasonSuccess, | ||
} | ||
case tferrors.IsApplyFailed(err): | ||
return xpv1.Condition{ | ||
Type: TypeAsyncOperation, | ||
Status: corev1.ConditionFalse, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: ReasonApplyFailure, | ||
Message: err.Error(), | ||
} | ||
case tferrors.IsDestroyFailed(err): | ||
return xpv1.Condition{ | ||
Type: TypeAsyncOperation, | ||
Status: corev1.ConditionFalse, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: ReasonDestroyFailure, | ||
Message: err.Error(), | ||
} | ||
default: | ||
return xpv1.Condition{ | ||
Type: "Unknown", | ||
Status: corev1.ConditionFalse, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: "Unknown", | ||
Message: err.Error(), | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2021 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package errors | ||
|
||
type applyFailed struct { | ||
log string | ||
} | ||
|
||
func (a *applyFailed) Error() string { | ||
return a.log | ||
} | ||
|
||
// NewApplyFailed returns a new apply failure error with given logs. | ||
func NewApplyFailed(log string) error { | ||
return &applyFailed{log: log} | ||
} | ||
|
||
// IsApplyFailed returns whether error is due to failure of an apply operation. | ||
func IsApplyFailed(err error) bool { | ||
_, ok := err.(*applyFailed) | ||
return ok | ||
} | ||
|
||
type destroyFailed struct { | ||
log string | ||
} | ||
|
||
func (a *destroyFailed) Error() string { | ||
return a.log | ||
} | ||
|
||
// NewDestroyFailed returns a new destroy failure error with given logs. | ||
func NewDestroyFailed(log string) error { | ||
return &destroyFailed{log: log} | ||
} | ||
|
||
// IsDestroyFailed returns whether error is due to failure of a destroy operation. | ||
func IsDestroyFailed(err error) bool { | ||
_, ok := err.(*destroyFailed) | ||
return ok | ||
} |
Oops, something went wrong.