Skip to content

Commit

Permalink
feat: able to join peer into channels;bug fix on channel creation
Browse files Browse the repository at this point in the history
Signed-off-by: bjwswang <bjwswang@gmail>

Changelogs
    1. fixed channel creation bug: tlsca not working in fabric-ca
    2. able to join peers into channel
    3. save channel list in network.status.channels
    4. fix orderer override on network creation which should use tlsca in tls
    5. fix peer unit test
    6. fix golangci-lint test: bug from latest version of golangci-lint(golangci/golangci-lint-action#535)
  • Loading branch information
bjwswang committed Feb 1, 2023
1 parent 89b4f31 commit 87f61af
Show file tree
Hide file tree
Showing 46 changed files with 1,673 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yaml
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
version: v1.47.3
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yaml
Expand Up @@ -26,6 +26,7 @@ on:
env:
KUBECONFIG_PATH: /tmp/kubeconfig.yaml
OPERATOR_NAMESPACE: inttest
OPERATOR_USER_TYPE: sa
DOCKERCONFIGJSON: ${{ secrets.DOCKERCONFIGJSON }}
GO_VER: 1.18

Expand Down
42 changes: 42 additions & 0 deletions api/v1beta1/channel.go
Expand Up @@ -22,6 +22,10 @@ func init() {
SchemeBuilder.Register(&Channel{}, &ChannelList{})
}

func (channel *Channel) GetConnectionPorfile() string {
return "chan-" + channel.GetName() + "-connection-profile"
}

func (channel *Channel) GetChannelID() string {
return channel.GetName()
}
Expand All @@ -30,6 +34,17 @@ func (channel *Channel) GetMembers() []Member {
return channel.Spec.Members
}

func (channel *Channel) GetPeerCondition(peer NamespacedName) (int, PeerCondition) {
for index, p := range channel.Status.PeerConditions {
if p.String() == peer.String() {
return index, p
}
}
return -1, PeerCondition{
NamespacedName: peer,
}
}

func (channel *Channel) HasType() bool {
return channel.Status.CRStatus.Type != ""
}
Expand All @@ -41,3 +56,30 @@ func (channel *Channel) HasNetwork() bool {
func (channel *Channel) HashMembers() bool {
return len(channel.Spec.Members) > 0
}

func DifferChannelPeers(old []NamespacedName, new []NamespacedName) (added []NamespacedName, removed []NamespacedName) {
// cache in map
oldMapper := make(map[string]NamespacedName, len(old))
for _, m := range old {
oldMapper[m.Name] = m
}

// calculate differences
for _, m := range new {

// added: in new ,but not in old
if _, ok := oldMapper[m.Name]; !ok {
added = append(added, m)
continue
}

// delete the intersection
delete(oldMapper, m.Name)
}

for _, m := range oldMapper {
removed = append(removed, m)
}

return
}
33 changes: 27 additions & 6 deletions api/v1beta1/channel_types.go
Expand Up @@ -36,23 +36,44 @@ type ChannelSpec struct {
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Members []Member `json:"members"`

// Peers list all fabric peers joined at this channel
Peers []NamespacedName `json:"peers,omitempty"`

// Description for this Channel
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Description string `json:"description,omitempty"`
}

type PeerConditionType string

const (
PeerJoined PeerConditionType = "PeerJoined"
PeerError PeerConditionType = "PeerError"
)

// ChannelPeer is the IBPPeer which joins this channel
type ChannelPeer struct {
type PeerCondition struct {
NamespacedName `json:",inline"`
JoinedTime metav1.Time `json:"joinedTime,omitempty"`
// Type is the type of the condition.
Type PeerConditionType `json:"type"`
// Status is the status of the condition.
// Can be True, False, Unknown.
Status metav1.ConditionStatus `json:"status"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Unique, one-word, CamelCase reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// Human-readable message indicating details about last transition.
// +optional
Message string `json:"message,omitempty"`
}

// ChannelStatus defines the observed state of Channel
type ChannelStatus struct {
CRStatus `json:",inline"`

// Peers has been joined into this channel
Peers []ChannelPeer `json:"peers,omitempty"`
CRStatus `json:",inline"`
PeerConditions []PeerCondition `json:"peerConditions,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
15 changes: 15 additions & 0 deletions api/v1beta1/ibppeer.go
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/IBM-Blockchain/fabric-operator/pkg/util/image"
"github.com/IBM-Blockchain/fabric-operator/version"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

// +kubebuilder:object:generate=false
Expand Down Expand Up @@ -310,6 +311,20 @@ func (i *PeerImages) Override(requested *PeerImages, registryURL string, arch st
i.EnrollerTag = image.GetTag(arch, i.EnrollerTag, requested.EnrollerTag)
}

func (p *IBPPeer) GetNamespacedName() types.NamespacedName {
return types.NamespacedName{Namespace: p.Namespace, Name: p.Name}
}

/* Enrollment when IAM Enabled*/

func (p *IBPPeer) GetEnrollUser() string {
return p.Spec.Secret.Enrollment.Component.EnrollUser
}

func (p *IBPPeer) GetEnrollToken() string {
return p.Spec.Secret.Enrollment.Component.EnrollToken
}

func init() {
SchemeBuilder.Register(&IBPPeer{}, &IBPPeerList{})
}
38 changes: 38 additions & 0 deletions api/v1beta1/network.go
Expand Up @@ -51,3 +51,41 @@ func (network *Network) HasType() bool {
func (network *Network) HasMembers() bool {
return len(network.Spec.Members) != 0
}

func (networkStatus *NetworkStatus) AddChannel(channel string) bool {
var conflict bool

for _, f := range networkStatus.Channels {
if f == channel {
conflict = true
break
}
}

if !conflict {
networkStatus.Channels = append(networkStatus.Channels, channel)
}

return conflict
}

func (networkStatus *NetworkStatus) DeleteChannel(channel string) bool {
var exist bool
var index int

channels := networkStatus.Channels

for curr, f := range channels {
if f == channel {
exist = true
index = curr
break
}
}

if exist {
networkStatus.Channels = append(channels[:index], channels[index+1:]...)
}

return exist
}
2 changes: 2 additions & 0 deletions api/v1beta1/network_types.go
Expand Up @@ -48,6 +48,8 @@ type NetworkSpec struct {
// NetworkStatus defines the observed state of Network
type NetworkStatus struct {
CRStatus `json:",inline"`
// Channels in this network
Channels []string `json:"channels,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
27 changes: 0 additions & 27 deletions api/v1beta1/organization.go
Expand Up @@ -58,33 +58,6 @@ func (organization *Organization) HasType() bool {
return organization.Status.CRStatus.Type != ""
}

func DifferClients(old []string, new []string) (added []string, removed []string) {
// cache in map
oldMapper := make(map[string]struct{}, len(old))
for _, c := range old {
oldMapper[c] = struct{}{}
}

// calculate differences
for _, c := range new {

// added: in new ,but not in old
if _, ok := oldMapper[c]; !ok {
added = append(added, c)
continue
}

// delete the intersection
delete(oldMapper, c)
}

for c := range oldMapper {
removed = append(removed, c)
}

return
}

func (organizationStatus *OrganizationStatus) AddFederation(federation NamespacedName) bool {
var conflict bool

Expand Down
50 changes: 30 additions & 20 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 32 additions & 3 deletions config/crd/bases/ibp.com_channels.yaml
Expand Up @@ -73,6 +73,16 @@ spec:
network:
description: Network which this channel belongs to
type: string
peers:
description: Peers list all fabric peers joined at this channel
items:
properties:
name:
type: string
namespace:
type: string
type: object
type: array
required:
- license
- members
Expand All @@ -93,18 +103,37 @@ spec:
description: Message provides a message for the status to be shown
to customer
type: string
peers:
description: Peers has been joined into this channel
peerConditions:
items:
description: ChannelPeer is the IBPPeer which joins this channel
properties:
joinedTime:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
format: date-time
type: string
message:
description: Human-readable message indicating details about
last transition.
type: string
name:
type: string
namespace:
type: string
reason:
description: Unique, one-word, CamelCase reason for the condition's
last transition.
type: string
status:
description: Status is the status of the condition. Can be True,
False, Unknown.
type: string
type:
description: Type is the type of the condition.
type: string
required:
- status
- type
type: object
type: array
reason:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/ibp.com_networks.yaml
Expand Up @@ -968,6 +968,11 @@ spec:
status:
description: NetworkStatus defines the observed state of Network
properties:
channels:
description: Channels in this network
items:
type: string
type: array
errorcode:
description: ErrorCode is the code of classification of errors
type: integer
Expand Down

0 comments on commit 87f61af

Please sign in to comment.